Capture all keystrokes on a GUI

Get help with using AutoHotkey and its commands and hotkeys
JJohnston2
Posts: 193
Joined: 24 Jun 2015, 23:38

Capture all keystrokes on a GUI

30 Jun 2017, 17:09

If you open the "Run" dialog in Windows, you can type into an Edit control while simultaneously viewing a popup list of auto-complete options that can be navigated using up/down arrows. Even while you navigate this list with up/down arrows, you can also still continue to type (because the Edit control remains active/focused), and the characters typed will be appended to the Edit control contents.

With a GUI that is somewhat similar to the Run dialog design, using an Edit control and a ListBox control, is there a way to capture all user keystrokes while the ListBox is focused, and re-route those back the Edit control (along with re-focusing the Edit control) if the user starts typing?

For navigation keystrokes (up/down arrows for example), it's easy enough to use (or dynamically enable) hotkeys that check which control is active, and take appropriate action (say the top or bottom of the ListBox is focused and I want the next up/down navigation to re-focus the cursor elsewhere--easy to do using Up:: or Down:: with appropriate #If directives)

For alphanumeric keys, is there a way to capture all keystrokes without having hotkeys for all of them? In other words, I would prefer not to have to do something like:

Code: Select all

a::
b::
...
z::
A::
B::
...
Z::
[every typable character]::
    doSomething()
Return
If I use OnMessage() and WM_KEYDOWN() keyboard handler, I can detect if the user is typing something alphanumeric, but I don't have the exact keystroke pressed... i.e., it can't be detected properly and appended to the current Edit control contents. In most cases wParam can be compared to correctly determine if a letter has been typed, but using chr(wParam) does not always reduplicate the correct character typed (because it misses other things like modifiers and extended keys). It is possible to use wParam comparison to detect an alphanumeric has been typed, and refocus to the Edit control, but then the first keystroke gets missed until the user types further in the Edit control. Also, A_PriorKey will not be updated at the time WM_KEYDOWN() executes.

Anyone have any clever tricks to capture all keystrokes on the GUI? Or potentially all keystrokes to a particular control (in this case the ListBox). Is it possible to get close to duplicating the keystroke behavior in the Windows run box, which is very similar to this application?
Guest

Re: Capture all keystrokes on a GUI

01 Jul 2017, 02:24

Are you talking about an AHK gui/edit control? If so just assign a gLabel to it and capture the contents (Submit or GuiControlGet).

Apart from Typing Aid these scripts may be useful:
https://autohotkey.com/board/topic/6849 ... iedit-v02/
https://autohotkey.com/board/topic/5835 ... ompletion/
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capture all keystrokes on a GUI

01 Jul 2017, 09:41

This script is pretty good:

Retrieve Key Names from OnMessage WM_KeyDown - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/7011 ... ntry444473
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
JJohnston2
Posts: 193
Joined: 24 Jun 2015, 23:38

Re: Capture all keystrokes on a GUI

02 Jul 2017, 18:09

>Are you talking about an AHK gui/edit control?

No. Talking about detecting keystrokes when a ListBox is active, not a an Edit control.

>https://autohotkey.com/board/topic/5835 ... ompletion/

This auto-completion script is neat! Very close to the type of GUI interface I was looking for. I see the implementation is basically just to refocus back to the edit control when the ListBox selection/value changes, that way you don't have to worry about artificially capturing keystrokes to another control, they just go straight to the Edit control

@jeeswg: Very nice script for retrieving key names from WM_KeyDown... hadn't seen that before... might come in handy at some point, thank you.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], haichen, hasantr, jmasiak, Rohwedder, RubbeH and 41 guests