Jump to content

Recommended Posts

Posted (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 by TXTechie
Posted

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
Posted

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? 

Posted (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 by TheXman
Posted (edited)

Hi TXTechie
Maybe a dummy control triggered by several Accelerators keys ?

#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 by pixelsearch
explanations added.

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

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?

Posted

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!!!

Posted
  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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...