hiimjoey11 Posted September 30, 2014 Posted September 30, 2014 I want to constantly have a GUI window open, and ONLY capture the "ENTER" key when that GUI window is focused (user is in that window). For example, I have this GUI set so when i press my Enter key it will refresh all my data. That works perfectly, except if I have that GUI window open and try and use my enter key anywhere else (browser, notepad, etc) it will still capture it. How can I only capture the ENTER button if the GUI is in focus? I am using this code to capture the enter key! HotKeySet("{ENTER}", "Enter") Thanks!
Moderators Melba23 Posted September 30, 2014 Moderators Posted September 30, 2014 hiimjoey11,Look at GUISetAccelerators in the Help file - it does exactly what you wish. 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
hiimjoey11 Posted September 30, 2014 Author Posted September 30, 2014 hiimjoey11, Look at GUISetAccelerators in the Help file - it does exactly what you wish. M23 hmm I don't think I am doing this right.. expandcollapse popup#include <array.au3> #include <file.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Form", 240, 118, 192, 124) $Input1 = GUICtrlCreateInput("", 16, 16, 208, 28,$ES_CENTER) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("", 16, 48, 208, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("", 16, 80, 208, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Dim $EnterArray[1][2] = [["{ENTER}", Enter()]] GUISetAccelerators($EnterArray) ;HotKeySet("{ENTER}", "Enter") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $copy = GUICtrlRead($Button1) ClipPut($copy) Case $Button2 $copy = GUICtrlRead($Button2) ClipPut($copy) EndSwitch WEnd Func Enter() GUICtrlSetData($Button1, $var1) GUICtrlSetData($Button2, $var2) EndFunc ;==>Enter
Moderators Melba23 Posted September 30, 2014 Moderators Posted September 30, 2014 hiimjoey11,That code makes no sense. When you press a button you read its text (and there is none to read) to the clipboard - when you want to press ENTER you set the text of the buttons to unknown variables ($var1/2) - and so the buttons still have no text. Overall I am not really surprised you cannot make it work. As to the GUISetAccelerators section - you need to link the key to a control, not a function - the Help file is quite clear about this. So you will need to add a dummy control to the GUI and then look for it to be fired in the idle loop. But we are getting ahead of ourselves here as until the rest of the script is sorted, it matters little. Please explain what you are trying to do and then we can look into getting the correct code to do it. 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
hiimjoey11 Posted September 30, 2014 Author Posted September 30, 2014 hiimjoey11, That code makes no sense. When you press a button you read its text (and there is none to read) to the clipboard - when you want to press ENTER you set the text of the buttons to unknown variables ($var1/2) - and so the buttons still have no text. Overall I am not really surprised you cannot make it work. As to the GUISetAccelerators section - you need to link the key to a control, not a function - the Help file is quite clear about this. So you will need to add a dummy control to the GUI and then look for it to be fired in the idle loop. But we are getting ahead of ourselves here as until the rest of the script is sorted, it matters little. Please explain what you are trying to do and then we can look into getting the correct code to do it. M23 I left out the variables because it was information that I didn't want to post to a forum.. For testing purposes, here is working code: expandcollapse popup#include <array.au3> #include <file.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Form", 240, 118, 192, 124) $Input1 = GUICtrlCreateInput("", 16, 16, 208, 28,$ES_CENTER) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("", 16, 48, 208, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("", 16, 80, 208, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Dim $EnterArray[1][2] = [["{ENTER}", Enter()]] GUISetAccelerators($EnterArray) ;HotKeySet("{ENTER}", "Enter") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $copy = GUICtrlRead($Button1) ClipPut($copy) Case $Button2 $copy = GUICtrlRead($Button2) ClipPut($copy) EndSwitch WEnd Func Enter() $var1 = "test" $var2 = "test2" GUICtrlSetData($Button1, $var1) GUICtrlSetData($Button2, $var2) EndFunc ;==>Enter Now what I want to do, is type something in the input box, then when I press enter it will GuiCtrlSetData the two buttons. Then there will be two buttons with information that I can copy once I click on them. Now when you say create a dummy control, do you mean create another button on the gui that calls the Enter function or am i misinterpreting this whole thing? Thanks for the help!
hiimjoey11 Posted September 30, 2014 Author Posted September 30, 2014 I tried doing what you said! And it kind of works, but not completely. expandcollapse popup#include <array.au3> #include <file.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Form", 240, 118, 192, 124) $Input1 = GUICtrlCreateInput("", 16, 16, 208, 28,$ES_CENTER) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("", 16, 48, 208, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("", 16, 80, 208, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button3 = GUICtrlCreateButton("", 16, 80, 208, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Dim $EnterArray[1][2] = [["{ENTER}", $Button3]] GUISetAccelerators($EnterArray) ;HotKeySet("{ENTER}", "Enter") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $copy = GUICtrlRead($Button1) ClipPut($copy) Case $Button2 $copy = GUICtrlRead($Button2) ClipPut($copy) Case $Button3 Enter() EndSwitch WEnd Func Enter() $var1 = "test" $var2 = "test2" GUICtrlSetData($Button1, $var1) GUICtrlSetData($Button2, $var2) EndFunc ;==>Enter
Moderators Solution Melba23 Posted September 30, 2014 Moderators Solution Posted September 30, 2014 hiimjoey11,This works for me - read the comments to see what I meant about needing a dummy control: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> $Form1_1 = GUICreate("Form", 240, 118, 192, 124) $Input1 = GUICtrlCreateInput("", 16, 16, 208, 28, $ES_CENTER) $Button1 = GUICtrlCreateButton("", 16, 48, 208, 25) $Button2 = GUICtrlCreateButton("", 16, 80, 208, 25) ; Create a dummy control for the accelerator to action $cEnter_Dummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; Link the key to the control Local $EnterArray[1][2] = [["{ENTER}", $cEnter_Dummy]] GUISetAccelerators($EnterArray) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $copy = GUICtrlRead($Button1) ClipPut($copy) Case $Button2 $copy = GUICtrlRead($Button2) ClipPut($copy) Case $cEnter_Dummy ; Look for the dummy control linked to the accelerator being fired Enter() ; Run the function EndSwitch WEnd Func Enter() $var1 = "test" $var2 = "test2" GUICtrlSetData($Button1, $var1) GUICtrlSetData($Button2, $var2) EndFunc ;==>EnterAll clear now? 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
hiimjoey11 Posted September 30, 2014 Author Posted September 30, 2014 hiimjoey11, This works for me - read the comments to see what I meant about needing a dummy control: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> $Form1_1 = GUICreate("Form", 240, 118, 192, 124) $Input1 = GUICtrlCreateInput("", 16, 16, 208, 28, $ES_CENTER) $Button1 = GUICtrlCreateButton("", 16, 48, 208, 25) $Button2 = GUICtrlCreateButton("", 16, 80, 208, 25) ; Create a dummy control for the accelerator to action $cEnter_Dummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; Link the key to the control Local $EnterArray[1][2] = [["{ENTER}", $cEnter_Dummy]] GUISetAccelerators($EnterArray) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $copy = GUICtrlRead($Button1) ClipPut($copy) Case $Button2 $copy = GUICtrlRead($Button2) ClipPut($copy) Case $cEnter_Dummy ; Look for the dummy control linked to the accelerator being fired Enter() ; Run the function EndSwitch WEnd Func Enter() $var1 = "test" $var2 = "test2" GUICtrlSetData($Button1, $var1) GUICtrlSetData($Button2, $var2) EndFunc ;==>Enter All clear now? M23 WHOOPS! GuiCtrlCreateDummy() is a function lol Yes, makes perfect sense! Thanks for introducing me to such a useful feature! It works perfect.
Moderators Melba23 Posted September 30, 2014 Moderators Posted September 30, 2014 hiimjoey11,Great. Of course you can link the accelerator to an existing control if there is a suitable one - we only needed a dummy here because none of the existing controls fired that particular function. M23 hiimjoey11 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
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