Jump to content

How can I limit keyboard input to this GUI?


timmy2
 Share

Recommended Posts

A graphic is already on screen showing the meanings of the following keys: j, k, l.

At the point when that graphic appears I want my script to then wait for the user to press any of those keys.  My script will respond appropriately.

I found an old post by zackrspv that led me to the following script. My question is: how can I limit keyboard input to this GUI? I don't want the user's keystrokes to be seen by any other program that might be running. I cannot figure out how to incorporate the BlockInputEX UDF into my script, plus I'm not sure my approach is even the best solution.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$form = GUICreate("test", 500, 500,BitOR($WS_SYSMENU,$WS_POPUP))

$SBack = GUICtrlCreateDummy()
$SPause = GUICtrlCreateDummy()
$SForward = GUICtrlCreateDummy()
Dim $AccelKeys[3][2] = [["j", $SBack],["k", $SPause],["l", $SForward]]
GUISetAccelerators($AccelKeys)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $SBack
            ConsoleWrite("back" & @CRLF)
        Case $SPause
            ConsoleWrite("pause" & @CRLF)
        Case $SForward
            ConsoleWrite("forward" & @CRLF)
    EndSwitch
WEnd
Edited by timmy2
Link to comment
Share on other sites

  • Moderators

timmy2,

Accelerator keys are automatically limited to your GUI when it is active - if your GUI is not active than they are useable by any active GUI. So if your graphic is being displayed in the active GUI - which you imply is the case - those keys will be trapped by that GUI. :)

By the way, you are not creating your GUI correctly - there are a couple of parameters missing: ;)

$form = GUICreate("test", 500, 500, -1, -1 ,BitOR($WS_SYSMENU,$WS_POPUP))
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

timmy2,

Accelerator keys are automatically limited to your GUI when it is active - if your GUI is not active than they are useable by any active GUI. So if your graphic is being displayed in the active GUI - which you imply is the case - those keys will be trapped by that GUI. :)

By the way, you are not creating your GUI correctly - there are a couple of parameters missing: ;)

$form = GUICreate("test", 500, 500, -1, -1 ,BitOR($WS_SYSMENU,$WS_POPUP))
M23

 

 

Thank you, Melba23 for replying. 

(I'm chuckling as I write this, being an idiot keyboard monkey who discovered he accidently typed a line from Hamlet.)

I realize the correct syntax for GUICreate requires the left and top values (-1, -1) but if I add those values my formerly invisible GUI becomes a white box, which I don't want. I'm tempted to enjoy my newly discovered hidden feature in GUICreate but for the sake of proper usage do you see anything wrong with changing the GUICreate statement to:

$form = GUICreate("test", 0, 0,-1, -1, BitOR($WS_SYSMENU,$WS_POPUP))

All I want is an invisible multiple-choice single-keystroke-to-continue routine that at least when active doesn't pass through keystrokes. If there's a better way please -- somebody -- show me.

While I've got your attention (if I do), can you tell me if it's possible to use the BlockInputEX UDF with my script, allows excepting a specific window?  I tried blocking all keyboard input with the exception of the handle $form but still NO input was allowed.

Edited by timmy2
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...