lyledg Posted February 7, 2008 Posted February 7, 2008 (edited) Hi allI am trying to activate the hotkey function with using the delete key, but only want it usable if an item is highlighted and in focus in the listviewexpandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Opt('MustDeclareVars', 1) $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work Global $LISTVIEW Global Const $Yes = 6, $No = 7 HotKeySet("{Delete}", "_Removeitem") _Main() Func _Main() Local $GUI, $hImage $GUI = GUICreate("(External) ListView Create", 400, 300) $LISTVIEW = _GUICtrlListView_Create ($GUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle ($LISTVIEW, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState() ; Load images $hImage = _GUIImageList_Create () _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap ($LISTVIEW, 0xFF0000, 16, 16)) _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap ($LISTVIEW, 0x00FF00, 16, 16)) _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap ($LISTVIEW, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList ($LISTVIEW, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn ($LISTVIEW, 0, "Column 1", 100) _GUICtrlListView_InsertColumn ($LISTVIEW, 1, "Column 2", 100) _GUICtrlListView_InsertColumn ($LISTVIEW, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem ($LISTVIEW, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem ($LISTVIEW, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem ($LISTVIEW, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem ($LISTVIEW, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem ($LISTVIEW, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem ($LISTVIEW, "Row 3: Col 1", 2) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Func _Removeitem() Local $win, $CurrentIndexSelected $Win = WinActive("(External) ListView Create") If $Win <> 0 Then $CurrentIndexSelected = _GUICtrlListView_GetNextItem($LISTVIEW) ;Get the item index in the listview If $CurrentIndexSelected <= -1 Then MsgBox(262192, "No items", "No items to delete") Else If MsgBox(262180, "Remove", "Are you sure you want to delete the highlighted item(s)?") = $Yes Then _GUICtrlListView_DeleteItemsSelected(ControlGetHandle("", "", $LISTVIEW)) Else Return EndIf EndIf Else HotKeySet("{Delete}") EndIf EndFuncWhen I try and use the delete key to delete some data on say an input box whilst the gui is running, The Hotkey wants to delete am item out of the Listviewbasically, how do I ensure that the Hotkey is ONLY used and associated with the listview items? Edited February 7, 2008 by lyledg
AdmiralAlkex Posted February 7, 2008 Posted February 7, 2008 You can use GUICtrlGetState() to check if the listview has focus .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
lyledg Posted February 8, 2008 Author Posted February 8, 2008 Unfortunately that does not work Adjusted code below expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Opt('MustDeclareVars', 1) $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work Global $LISTVIEW Global Const $Yes = 6, $No = 7 HotKeySet("{Delete}", "_Removeitem") _Main() Func _Main() Local $GUI, $hImage $GUI = GUICreate("(External) ListView Create", 600, 500) $LISTVIEW = _GUICtrlListView_Create ($GUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle ($LISTVIEW, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState() ; Load images $hImage = _GUIImageList_Create () _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap ($LISTVIEW, 0xFF0000, 16, 16)) _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap ($LISTVIEW, 0x00FF00, 16, 16)) _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap ($LISTVIEW, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList ($LISTVIEW, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn ($LISTVIEW, 0, "Column 1", 100) _GUICtrlListView_InsertColumn ($LISTVIEW, 1, "Column 2", 100) _GUICtrlListView_InsertColumn ($LISTVIEW, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem ($LISTVIEW, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem ($LISTVIEW, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem ($LISTVIEW, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem ($LISTVIEW, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem ($LISTVIEW, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem ($LISTVIEW, "Row 3: Col 1", 2) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Func _Removeitem() Local $win, $CurrentIndexSelected, $State $Win = WinActive("(External) ListView Create") If $Win <> 0 Then $State = GUICtrlGetState($LISTVIEW) msgbox (0,"state",StringFormat("GUICtrlRead=%d\nGUICtrlGetState=%d",GUICtrlRead($LISTVIEW),GUICtrlGetState($LISTVIEW))) $CurrentIndexSelected = _GUICtrlListView_GetNextItem($LISTVIEW) ;Get the item index in the listview If $CurrentIndexSelected <= -1 Then MsgBox(262192, "No items", "No items to delete") Else If MsgBox(262180, "Remove", "Are you sure you want to delete the highlighted item(s)?") = $Yes Then _GUICtrlListView_DeleteItemsSelected(ControlGetHandle("", "", $LISTVIEW)) Else Return EndIf EndIf Else HotKeySet("{Delete}") EndIf EndFunc Also, see attached document for screenshots_GUICtrlListView_Create_focus.doc
lyledg Posted February 8, 2008 Author Posted February 8, 2008 Solved!#include <GuiConstants.au3> $GUI = GUICreate("Test Edit") $Edit = GUICtrlCreateEdit("", 20, 50, 150, 150) $Button = GUICtrlCreateButton("Button", 20, 210) GUICtrlSetState(-1, $Gui_Focus) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 Exit EndSwitch If _IsFocused($GUI, $Edit) Then Sleep(20) HotKeySet("{TAB}", "TabPress") Else HotKeySet("{TAB}") EndIf WEnd Func TabPress() ;$OldClip = ClipGet() ;ClipPut(@TAB) ;Send("+{INSERT}") ;ClipPut($OldClip) Send("^{TAB}") ;This is the tip from Siao - Thanks! EndFunc Func _IsFocused($hWnd, $nCID) Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd)) EndFuncThanks to MSCreator and Siaohttp://www.autoitscript.com/forum/index.ph...p;hl=_IsFocused
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now