Hallo,
wie kann man einen HotKey auf eine ListView setzen? Z.b. ich habe eine ListView, wähle einen Item aus, drücke Entf und nun soll eine Msgbox erscheinen. Wie macht man sowas?
Hallo,
wie kann man einen HotKey auf eine ListView setzen? Z.b. ich habe eine ListView, wähle einen Item aus, drücke Entf und nun soll eine Msgbox erscheinen. Wie macht man sowas?
Hey so würde es gehen:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WinApi.au3>
#include <Misc.au3>
Opt('GuiOnEventMode', 1)
[/autoit] [autoit][/autoit] [autoit]Global $cShow = False
GUICreate("listview items", 220, 170, -1, -1)
GuiSetOnEvent($GUI_EVENT_CLOSE, "_Terminate")
GUISetBkColor(0x00E0FFFF) ; will change background color
$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150)
$item1 = GUICtrlCreateListViewItem("item1|1|2", $listview)
$item2 = GUICtrlCreateListViewItem("Klick Mich!!|1|2", $listview)
$item3 = GUICtrlCreateListViewItem("item3|1|2", $listview)
$item4 = GUICtrlCreateListViewItem("item4|1|2", $listview)
$item5 = GUICtrlCreateListViewItem("item5|1|2", $listview)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
sleep(100)
While $cShow
sleep(10)
If _isPressed("2E") Then MsgBox(0,"Info!", "ENF wurde gedrückt!")
Wend
Wend
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $hWndFrom, $iCode
If Not IsHWnd($listview) Then $hWndFrom = GUICtrlGetHandle($listview)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $listview, $hWndFrom
Switch $iCode
Case $NM_CLICK
If _GUICtrlListView_GetItemSelected($listview, 1) Then
$cShow = True
Else
$cShow = False
EndIf
EndSwitch
EndSwitch
EndFunc
Func _Terminate()
Exit
EndFunc
ich würde es mit hotkeyset machen, da bei _ispressed die cpu hoch geht ...
Ich würd ungefähr so machen:
hotkeyset('{del}', '_del')
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WinApi.au3>
#include <Misc.au3>
GUICreate("listview items", 220, 170, -1, -1)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150)
$item1 = GUICtrlCreateListViewItem("item1|1|2", $listview)
$item2 = GUICtrlCreateListViewItem("Klick Mich!!|1|2", $listview)
$item3 = GUICtrlCreateListViewItem("item3|1|2", $listview)
$item4 = GUICtrlCreateListViewItem("item4|1|2", $listview)
$item5 = GUICtrlCreateListViewItem("item5|1|2", $listview)
GUISetState()
$msg=guigetmsg()
while $msg<>$GUI_EVENT_CLOSE
$msg=guigetmsg()
sleep(100) ;==> DEBUG
WEnd
func _del()
_GUICtrlListView_DeleteItemsSelected($listview)
EndFunc
So ist es am besten
ohne _IsPressed und Hotkeyset. und ENTF wird nur erkannt, wenn es in der ListView gedrückt wird:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WinApi.au3>
#include <Misc.au3>
Opt('GuiOnEventMode', 1)
[/autoit] [autoit][/autoit] [autoit]Global $ENTF_Pressed = False
[/autoit] [autoit][/autoit] [autoit]GUICreate("listview items", 220, 200, -1, -1)
GuiSetOnEvent($GUI_EVENT_CLOSE, "_Terminate")
GUISetBkColor(0x00E0FFFF) ; will change background color
$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150)
$item1 = GUICtrlCreateListViewItem("item1|1|2", $listview)
$item2 = GUICtrlCreateListViewItem("Klick Mich!!|1|2", $listview)
$item3 = GUICtrlCreateListViewItem("item3|1|2", $listview)
GUICtrlCreateInput("test", 10, 170,200,20)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
sleep(100)
If $ENTF_Pressed Then
$ENTF_Pressed = False
MsgBox(0, '', "ENTF gedrückt")
EndIf
Wend
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $hWndFrom, $iCode, $hWndListView=-1
If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $listview, $hWndListView
Switch $iCode
Case $LVN_KEYDOWN
Local $tagLVKEYDOWN = $tagNMHDR & "; USHORT wVKey; UINT flags;"
$tNMHDR = DllStructCreate($tagLVKEYDOWN,$lParam)
If DllStructGetData($tNMHDR,"wVKey") = 0x2E Then ; ENTF-Taste
$ENTF_Pressed = True
EndIf
EndSwitch
EndSwitch
EndFunc
Func _Terminate()
Exit
EndFunc
Mist an $LVN_KEYDOWN hab ich garnicht gedacht ![]()