DickWms Posted December 16, 2012 Posted December 16, 2012 I'm trying to catch non printing characters (like Delete, F5, Shifte F5, etc) when a user is typing into an Input Control. The sample code below doesn't work (the Input MsgBox only appears when the enter key is pressed and the Key Pressed MsgBox never appears). It appears to me this is because the Input Control doesn't send a GUI message every time a key stroke is received. So my question is how can I capture individual key presses, including non printing ones, to an Input Control? Or should I be using a different control? Thank you - Dick williams #include #include $window = GUICreate("Test", 200, 100) $inputBox = GUICtrlCreateInput ( "Input Box", 50, 50 , 100, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $inputBox MsgBox(0, "Input Box", "Case Executed") If _IsPressed(75) Then MsgBox(0, "Key Pressed", "F5") EndIf Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd
Moderators Melba23 Posted December 16, 2012 Moderators Posted December 16, 2012 DickWms,how can I capture individual key presses, including non printing ones, to an Input Control?Surely an input control is for inputting text - so why do you want to capture other keypresses as well? 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
DickWms Posted December 16, 2012 Author Posted December 16, 2012 The program will send Function Keys to another application's window and I want to use the Delete key as a short cut to erase all text in the Input Control. If there is a better control I'd be happy to use it. Dick Williams
Moderators Melba23 Posted December 16, 2012 Moderators Posted December 16, 2012 (edited) DickWms,If all you are looking for are those few keys then why not use _IsPressed in your idle loop? M23Edit:Here is how you could look for the "Delete" key to empty the input:#include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") $hGUI = GUICreate("Test", 500, 500) $cInput = GUICtrlCreateInput("", 10, 10, 200, 20) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($hDLL) Exit EndSwitch If _WinAPI_GetFocus() = GUICtrlGetHandle($cInput) And _IsPressed("2E", $hDLL) Then GUICtrlSetData($cInput, "") EndIf WEndAny help? Edited December 16, 2012 by Melba23 Xandy 1 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
DickWms Posted December 16, 2012 Author Posted December 16, 2012 Thank you - that looks promising. I will give it a try. Dick Williams
DickWms Posted December 16, 2012 Author Posted December 16, 2012 Yes - that is a great help and seems to be working fine. One more question - the application I'm writing uses a tab control and the input control is on tab0. I just wanted the Delete Key shortcut to work when tab0 is active. So I added a clause to your If statement and made it look like this: If _WinAPI_GetFocus() = GUICtrlGetHandle($cInput) And _IsPressed("2E", $hDLL) And GUICtrlRead($tab) = 0 This doesn't work as I expected. If I put text in the input control, click on another tab, hit the Delete key, and then return to tab0, the input contol will be blank. Dick Williams
Moderators Melba23 Posted December 17, 2012 Moderators Posted December 17, 2012 DickWms, A peculiarity of Windows is causing this. When you switch to another tab the whole content of the input is selected while the input also retains the keyboard focus - so pressing "Delete" still affects the input and replaces all content. You can see that quite clearly in this short script - just put some text into the input and then swap tabs. Whan you return to Tab 0 you will see that all the text in the input is highlighted (highlit?): #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cTab = GUICtrlCreateTab(10, 10, 480, 380) $cTab_0 = GUICtrlCreateTabItem("Tab 0") $cInput = GUICtrlCreateInput("", 50, 50, 200, 20) $cTab_1 = GUICtrlCreateTabItem("Tab 1") GUICtrlCreateTabItem("") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd The trick is to reset the focus to another control when you change tabs - like this: #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") $hGUI = GUICreate("Test", 500, 500) $cTab = GUICtrlCreateTab(10, 10, 480, 380) $cTab_0 = GUICtrlCreateTabItem("Tab 0") $cInput = GUICtrlCreateInput("", 50, 50, 200, 20) $cTab_1 = GUICtrlCreateTabItem("Tab 1") GUICtrlCreateTabItem("") $cButton = GUICtrlCreateButton("Test", 10, 450, 80, 30) ; <<<<< Just for the demo - you could use any control GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($hDLL) Exit Case $cTab ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< When tab is actioned GUICtrlSetState($cButton, $GUI_FOCUS) ; <<<<<<<<<<<<<< Change the focus EndSwitch If _WinAPI_GetFocus() = GUICtrlGetHandle($cInput) And _IsPressed("2E", $hDLL) And GUICtrlRead($cTab) = 0 Then GUICtrlSetData($cInput, "") While _IsPressed("2E", $hDLL) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< Not really necessary, but just wait until the key is released Sleep(10) WEnd EndIf WEnd All clear? M23 Xandy 1 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
DickWms Posted December 17, 2012 Author Posted December 17, 2012 Yes - it's all clear now. Thank you again - Dick Williams
Moderators Melba23 Posted December 17, 2012 Moderators Posted December 17, 2012 DickWms, Glad I could be of help. 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
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