Jump to content

GUI Keyboard Input


Artisan
 Share

Go to solution Solved by Melba23,

Recommended Posts

I am creating a GUI that uses mostly GDI work, and a few standard controls. This is the same one that I posted about >before. When my GUI has focus, I want to watch for the user to press the numbers 1-9. I do not want to monitor keyboard input when the GUI does not have focus. There are multiple ways to do this. Here are my ideas so far:

  1. Use _IsPressed. Currently I'm using the standard GUIGetMsg() loop, but I could easily convert to GUIOnEventMode and poll _IsPressed continuously. I haven't tested yet, but I assume it fires whether or not the GUI has focus. That's easy to watch for, though.
  2. Register WM_KEYUP. Oh how I wish that GUI controls didn't hog this message for themselves! The only way to make this work is to convert my GUI controls into "manual GDI controls" that I draw & manage myself. Then the GUI itself will receive WM_KEYUP (etc) messages. (I've already tested that with an empty GUI.) For GUI controls, all I have is a Tab control with a button on the first tab, and 2 buttons and a ListBox on the 2nd tab. Given the GDI work I'm already doing, it wouldn't be that much more work to make it happen. It also gives me more control over the style and look of things.
  3. Use HotKeySet. I would have to set and unset all 9 when the GUI gains/loses focus. This doesn't seem like the most elegant solution, but it's a good fall-back.

Technically, I could hook the keyboard, but that's really shady and goes way beyond what I need. I'm not going to do that.

So, which way is "best"? How do you define "best"? I think #1 is my best option, but I want to know what everyone else thinks and why. Maybe there's a better way? I doubt I've thought of everything. ;)

Edited by Artisan
Link to comment
Share on other sites

  • Moderators
  • Solution

Artisan,

Have you thought of Accelerator keys? They are only active when your GUI is active - sound like just the job. ;)

GUISetAccelerators is the function you need. ;)

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

GUISetAccelerators is the function you need. ;)

 

And a 2-D array ;)

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

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