TXTechie Posted October 7, 2020 Posted October 7, 2020 (edited) I've developed a simple GUI form with a background image and just two buttons. I don't want either of the two buttons to accept any keyboard input so that the user doesn't inadvertently or accidentally press the Tab and/or Enter keys while typing when my GUI is launched via SCCM deployment. I've set both buttons to have the $GUI_SHOW+$GUI_ENABLE+$GUI_NOFOCUS states, but both of them are in the tab order (I cannot find a way to remove them both from the tab order so that pressing the Tab key will NOT cycle between them) and one of them still has the default focus so that when a user presses the Enter key one of the buttons gets chosen (whether or not that was the intention of the user). Is there any way that I can basically disable keyboard input (at least for the Tab and Enter keys) to my GUI and/or the two buttons on the GUI form so that only mouse actions will select (or otherwise interact with) the appropriate button? Or, is there some other way to accomplish this as a workaround? Regards, TX Techie Edited October 7, 2020 by TXTechie
seadoggie01 Posted October 7, 2020 Posted October 7, 2020 You can use _IsPressed to check if either the Tab or Enter keys are down when the event fires. If they are, cancel the event All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Reveal hidden contents My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
TXTechie Posted October 7, 2020 Author Posted October 7, 2020 Thank you, seadoggie01. It looks like I could use _IsPressed as a workaround, but how would I cancel the event after capturing it via _IsPressed? I am also concerned about the performance of my GUI, if I used _IsPressed (even if I use the recommendation of opening the 'user32.dll', as stated in the Help). Is there not a "better" more of a "best practice" way within AutoIt to do what I want to do?
TheXman Posted October 7, 2020 Posted October 7, 2020 (edited) On 10/7/2020 at 3:30 PM, TXTechie said: Is there not a "better" more of a "best practice" way within AutoIt to do what I want to do? Expand I don't know if you consider this a "better" way but it is a different way. If you look at _GUICtrlButton_Create() example in the Help File, you will see how you can capture whether the button is pushed or clicked and determine whether you want to handle the message or let the default handler handle the message. Edited October 7, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
pixelsearch Posted October 7, 2020 Posted October 7, 2020 (edited) Hi TXTechie Maybe a dummy control triggered by several Accelerators keys ? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGUI = GUICreate("Tab-Enter-Space deactivated", 400, 200) Local $idButton1 = GUICtrlCreateButton("Button 1", 30, 170, 85, 25) Local $idButton2 = GUICtrlCreateButton("Button 2", 120, 170, 85, 25) Local $idButton3 = GUICtrlCreateButton("Button 3", 210, 170, 85, 25) Local $idButton4 = GUICtrlCreateButton("Button 4", 300, 170, 85, 25) Local $idDummy = GUICtrlCreateDummy() Local $aAccelKeys[3][2] = [["{TAB}", $idDummy], ["{ENTER}", $idDummy], ["{SPACE}", $idDummy]] GUISetAccelerators($aAccelKeys, $hGUI) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idDummy ; eat unwanted keys Case $idButton1 ConsoleWrite("Button1 (mouse)" & @lf) Case $idButton2 ConsoleWrite("Button2 (mouse)" & @lf) Case $idButton3 ConsoleWrite("Button3 (mouse)" & @lf) Case $idButton4 ConsoleWrite("Button4 (mouse)" & @lf) EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Space was added to the list as it triggers a selected button. Also the 4 direction keys seem to select the buttons controls. If you don't need them elsewhere in the GUI. just add them to the pack : Local $aAccelKeys[7][2] = [["{TAB}", $idDummy], ["{ENTER}", $idDummy], ["{SPACE}", $idDummy], _ ["{LEFT}", $idDummy], ["{RIGHT}", $idDummy], ["{UP}", $idDummy], ["{DOWN}", $idDummy]] Edited October 7, 2020 by pixelsearch explanations added. "I think you are searching a bug where there is no bug... don't listen to bad advice."
TXTechie Posted October 7, 2020 Author Posted October 7, 2020 This looks is working EXACTLY how I want it to, pixelsearch! Thank you for this! However, I'm using OnEventMode [Opt("GUIOnEventMode", 1)], how would I code this for OnEventMode?
TXTechie Posted October 7, 2020 Author Posted October 7, 2020 Never mind. I've got it working, basically just using the following lines of code before displaying the GUI: Local $idDummy = GUICtrlCreateDummy() Local $aAccelKeys[7][2] = [["{TAB}", $idDummy], ["{ENTER}", $idDummy], ["{SPACE}", $idDummy], ["{LEFT}", $idDummy], _ ["{RIGHT}", $idDummy], ["{UP}", $idDummy], ["{DOWN}", $idDummy]] GUISetAccelerators($aAccelKeys, $hGUI) This is AWESOME, pixelsearch! Thank you so VERY MUCH!!!
pixelsearch Posted October 7, 2020 Posted October 7, 2020 "I think you are searching a bug where there is no bug... don't listen to bad advice."
seadoggie01 Posted October 7, 2020 Posted October 7, 2020 On 10/7/2020 at 3:30 PM, TXTechie said: how would I cancel the event after capturing it via _IsPressed? Expand If you're using OnEvent mode, you would use Return. If you're in a Switch statement, you probably have it wrapped in a loop, so you'd use ContinueLoop Pixelsearch's answer seems more appropriate, however All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Reveal hidden contents My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
TXTechie Posted October 9, 2020 Author Posted October 9, 2020 Thank you, seadoggie01. I think I understand. Thank you for responding to my question!
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