Jump to content

Recommended Posts

Posted (edited)

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
  • Moderators
  • Solution
Posted

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:

  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
×
×
  • Create New...