VAN0 Posted May 24, 2010 Posted May 24, 2010 Hello. I must be missing something obvious, but I can't figure out how to "capture" when an item in list selected and DELETE key pressed. The whole routine deleting the selected item I'll figure out myself, just need help with keyboard part. Thank you. P.S. Something wrong with search engine on this forum? getting white page when trying search.
Moderators Melba23 Posted May 24, 2010 Moderators Posted May 24, 2010 (edited) VAN0, You could do it this way: #include <GUIConstantsEx.au3> #include <Misc.au3> $dll = DllOpen("user32.dll") $hGUI = GUICreate("Test", 500, 500) $hList = GUICtrlCreateList("", 10, 10, 480, 480) GUICtrlSetData($hList, "Line 1|Line 2|Line 3") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) Exit EndSwitch If _IsPressed("2E", $dll) Then ; Wait for key to be released to avoid multiple firing the code below While _IsPressed("2E", $dll) Sleep(10) WEnd If GUICtrlRead($hList) <> "" Then MsgBox(0, "", "DELETE pressed with an item selected") EndIf EndIf WEnd M23 Edit: Added code to wait for key release - it caused problems later in the script if not. Edited May 27, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
taietel Posted May 24, 2010 Posted May 24, 2010 (edited) I've added something at Melba's code: #include <GUIConstantsEx.au3> #include <Misc.au3> #include <GUIListBox.au3> $dll = DllOpen("user32.dll") $hGUI = GUICreate("Test", 500, 500) $hList = GUICtrlCreateList("", 10, 10, 480, 480) GUICtrlSetData($hList, "Line 1|Line 2|Line 3") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) Exit EndSwitch If _IsPressed("2E", $dll) Then Local $indice = _GUICtrlListBox_GetCurSel($hList) Local $iMsgBoxAnswer = MsgBox(36, "", "Are you sure?") Select Case $iMsgBoxAnswer = 6 ;Yes _GUICtrlListBox_DeleteString($hList, $indice) Case $iMsgBoxAnswer = 7 ;No ;Exit EndSelect EndIf WEnd [edit] I've used this in a right-click menu, because I didn't know how to use DELETE. Thank's Melba! Edited May 24, 2010 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
VAN0 Posted May 24, 2010 Author Posted May 24, 2010 Thank you very much guys, this is exactly what I needed! Works perfectly. P.S. now discovered another issue with _ArrayDelete(), I have to pause the script after using it, otherwise it corrupts array for some reason..
VAN0 Posted May 24, 2010 Author Posted May 24, 2010 (edited) Actually, I take it back, there is an issue with this method, it "capture" key press even when another program is opened, and even if list is not in currently in focus.. @taietel: would you share you right click menu code? I think both method would be more useful in this case. Thank you. Edited May 24, 2010 by VAN0
Moderators Melba23 Posted May 24, 2010 Moderators Posted May 24, 2010 VAN0, Can you post some code which shows this array corruption because I have not heard of it happening before. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Yashied Posted May 24, 2010 Posted May 24, 2010 Why not use GUISetAccelerators(). My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
taietel Posted May 24, 2010 Posted May 24, 2010 VAN0, of course! Here is a sample: expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 177, 267, 371, 201) $lstDiscipline = GUICtrlCreateList("", 8, 8, 161, 214) GUICtrlSetData($lstDiscipline, "Biologie|Chimie|Educatie Fizica si Sport|Fizica|Geografie|Istorie|Limba Engleza|Limba Franceza|Limba Romana|Matematica|Purtare|TIC") Global $lstDisciplinecontext = GUICtrlCreateContextMenu($lstDiscipline) Global $cmnuAdaugaDisciplina = GUICtrlCreateMenuItem("&Add discipline", $lstDisciplinecontext) Global $cmnuStergeDisciplina = GUICtrlCreateMenuItem("&Delete discipline", $lstDisciplinecontext) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cmnuAdaugaDisciplina AdaugaDisciplina() Case $cmnuStergeDisciplina StergeDisciplina() EndSwitch WEnd Func StergeDisciplina() Local $indice = _GUICtrlListBox_GetCurSel($lstDiscipline) Local $iMsgBoxAnswer = MsgBox(36, "Atentie!", "Esti sigur(a) ca vrei sa stergi?") Select Case $iMsgBoxAnswer = 6 ;Da _GUICtrlListBox_DeleteString($lstDiscipline, $indice) Case $iMsgBoxAnswer = 7 ;Nu Exit EndSelect EndFunc ;==>StergeDisciplina Func AdaugaDisciplina() Local $pozitie = MouseGetPos() Local $AdaugaDisciplina = GUICreate("Adauga Disciplina", 340, 40, $pozitie[0] + 5, $pozitie[1] + 5, BitOR($WS_SYSMENU, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS)) Local $txtAdaugaDisciplina = GUICtrlCreateInput("", 8, 8, 217, 21) Local $btnAdaugaDisciplina = GUICtrlCreateButton("Adauga...", 232, 7, 97, 25, $WS_GROUP) WinSetTrans("Adauga Disciplina", "", 240) GUISetState(@SW_SHOW, $AdaugaDisciplina) Do Local $actiune = GUIGetMsg() If $actiune = $btnAdaugaDisciplina Then Local $listaDiscipline = "" For $i = 0 To _GUICtrlListBox_GetCount($lstDiscipline) -1 $listaDiscipline &= _GUICtrlListBox_GetText($lstDiscipline, $i) & "|" Next Local $comparaLista = StringSplit($listaDiscipline,"|") If StringInStr(StringUpper($listaDiscipline), StringUpper(GUICtrlRead($txtAdaugaDisciplina))) Then MsgBox(48, "Situatii Statistice © 2010", "Disciplina " & StringUpper(GUICtrlRead($txtAdaugaDisciplina)) & " exista deja!") Else _GUICtrlListBox_AddString($lstDiscipline, StringUpper(GUICtrlRead($txtAdaugaDisciplina))) EndIf GUIDelete($AdaugaDisciplina) EndIf Until $actiune = $btnAdaugaDisciplina EndFunc ;==>AdaugaDisciplina The variables are in my language. I hope it's not an issue! Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Moderators Melba23 Posted May 24, 2010 Moderators Posted May 24, 2010 Yashied, Why not? VAN0, Here is the example reworked: #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $hList = GUICtrlCreateList("", 10, 10, 480, 480) GUICtrlSetData($hList, "Line 1|Line 2|Line 3") ; Set accelerator for Del $hDelKey = GUICtrlCreateDummy() Dim $AccelKeys[1][2]=[["{DELETE}", $hDelKey]] GUISetAccelerators($AccelKeys) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hDelKey If GUICtrlRead($hList) <> "" Then MsgBox(0, "", "DELETE pressed with an item selected") EndIf EndSwitch WEnd You choose! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Yashied Posted May 24, 2010 Posted May 24, 2010 (edited) It is better that DEL will be triggered only if List has a focus. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hDelKey If (_WinAPI_GetFocus() = GUICtrlGetHandle($hList)) And (GUICtrlRead($hList)) Then MsgBox(0, "", "DELETE pressed with an item selected") EndIf EndSwitch WEnd Edited May 24, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
KaFu Posted May 24, 2010 Posted May 24, 2010 It is better that DEL will be triggered only if List has a focus.Best Practice , will for sure add this to all of my programs... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
VAN0 Posted May 25, 2010 Author Posted May 25, 2010 Wow, guys, thank you very much, the last code works wonderful.@taietel:your example looks awesome, will try integrate it in my script Thanks.VAN0,Can you post some code which shows this array corruption because I have not heard of it happening before. M23After more testing it turned out to be some sort of conflict with your first del key code, for some bizarre reason all _Array... functions would return "0" (error 1 - Returns 0 if parameter is not an array), but if I add sleep(100), before an _ArrayUnique (or any other _Array function) it worked fine...very weird. I'll see if I can reproduce this weirdness in a sample code, otherwise we could blame my sloppy coding
Moderators Melba23 Posted May 25, 2010 Moderators Posted May 25, 2010 (edited) VAN0,I'll see if I can reproduce this weirdness in a sample codeI get no problems using _Array* functions with my code - nor would I expect any. Please do try and get some reproducer code. But if that proves too difficult, and you do not want to post your code in open forum but do not mind me seeing it, feel free to PM it to me so I can take a look. M23Edit: Clarity, I hope! Edited May 25, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
VAN0 Posted May 27, 2010 Author Posted May 27, 2010 (edited) Ok, I got everything working perfectly, thank you very much guys. @taietel: One little snag I found with your code: it showed context menu even if nothing selected in the list. In case someone searching for this, here is "fixed" version of your example, it shows "delete" option only when an item selected: expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 177, 267, 371, 201) $lstDiscipline = GUICtrlCreateList("", 8, 8, 161, 214) GUICtrlSetData($lstDiscipline, "Biologie|Chimie|Educatie Fizica si Sport|Fizica|Geografie|Istorie|Limba Engleza|Limba Franceza|Limba Romana|Matematica|Purtare|TIC") Global $lstDisciplinecontext = GUICtrlCreateContextMenu($lstDiscipline) Global $cmnuAdaugaDisciplina = GUICtrlCreateMenuItem("&Add discipline", $lstDisciplinecontext) Global $cmnuStergeDisciplina = GUICtrlCreateMenuItem("&Delete discipline", $lstDisciplinecontext) ;add delete option $cmnuStergeDisciplinaAdded = True GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") ;registering context menu event handler GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cmnuAdaugaDisciplina AdaugaDisciplina() Case $cmnuStergeDisciplina StergeDisciplina() EndSwitch WEnd Func StergeDisciplina() Local $indice = _GUICtrlListBox_GetCurSel($lstDiscipline) Local $iMsgBoxAnswer = MsgBox(36, "Atentie!", "Esti sigur(a) ca vrei sa stergi?") Select Case $iMsgBoxAnswer = 6 ;Da _GUICtrlListBox_DeleteString($lstDiscipline, $indice) Case $iMsgBoxAnswer = 7 ;Nu Exit EndSelect EndFunc ;==>StergeDisciplina Func AdaugaDisciplina() Local $pozitie = MouseGetPos() Local $AdaugaDisciplina = GUICreate("Adauga Disciplina", 340, 40, $pozitie[0] + 5, $pozitie[1] + 5, BitOR($WS_SYSMENU, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS)) Local $txtAdaugaDisciplina = GUICtrlCreateInput("", 8, 8, 217, 21) Local $btnAdaugaDisciplina = GUICtrlCreateButton("Adauga...", 232, 7, 97, 25, $WS_GROUP) WinSetTrans("Adauga Disciplina", "", 240) GUISetState(@SW_SHOW, $AdaugaDisciplina) Do Local $actiune = GUIGetMsg() If $actiune = $btnAdaugaDisciplina Then Local $listaDiscipline = "" For $i = 0 To _GUICtrlListBox_GetCount($lstDiscipline) -1 $listaDiscipline &= _GUICtrlListBox_GetText($lstDiscipline, $i) & "|" Next Local $comparaLista = StringSplit($listaDiscipline,"|") If StringInStr(StringUpper($listaDiscipline), StringUpper(GUICtrlRead($txtAdaugaDisciplina))) Then MsgBox(48, "Situatii Statistice © 2010", "Disciplina " & StringUpper(GUICtrlRead($txtAdaugaDisciplina)) & " exista deja!") Else _GUICtrlListBox_AddString($lstDiscipline, StringUpper(GUICtrlRead($txtAdaugaDisciplina))) EndIf GUIDelete($AdaugaDisciplina) EndIf Until $actiune = $btnAdaugaDisciplina EndFunc ;==>AdaugaDisciplina Func _WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam If $wParam <> GUICtrlGetHandle($lstDiscipline) Then Return $GUI_RUNDEFMSG ;we only going to handle context menu on list, all others carry on as is. Local $index = _GUICtrlListBox_GetCurSel($lstDiscipline) If $index <> -1 Then If Not $cmnuStergeDisciplinaAdded Then Global $cmnuStergeDisciplina = GUICtrlCreateMenuItem("&Delete discipline", $lstDisciplinecontext) ;add delete option $cmnuStergeDisciplinaAdded = True Else GUICtrlDelete($cmnuStergeDisciplina) ;remove "delete" option $cmnuStergeDisciplinaAdded = False EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_CONTEXTMENU Edited May 27, 2010 by VAN0
taietel Posted May 27, 2010 Posted May 27, 2010 Thank you VAN0! I've modified my script with your suggestion! Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
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