Key Equivalents within Dialog

Started by PaulSamuelson, November 27, 2018, 07:45:07 AM

Previous topic - Next topic

PaulSamuelson

I would like to add keyboard-operation to a series of controls in a Dialog. I need about 9 keys and would like to use the numeric keypad. It could be a special mode of the dialog, to eliminate interference with other controls.

I have played with WaitForKeyEx(), but it seems kind of awkward. Maybe I am putting it in the wrong place in my Dialog callback. Could this work? Where in the callback should the WaitForKeyEx() routine be located?

Is there any other way to activate controls from the keyboard? Menus require an additional key (alt- ). Can buttons be triggered by a key?

Thanks,

Paul Samuelson

JTaylor

If you have buttons for them, putting an & in front of the desired shortcut will make Alt+Key work.

You can use WaitForKeyEx() in a callback.  It works okay depending on the script.   It can be a bit resource intensive if not careful.   Attached is an example using this method.

I have attached something Tony posted a few years ago that uses MenuItems that might be a possibility.

Jim

PaulSamuelson

Thanks Jim (and Tony). I think that will help.

Paul

PaulSamuelson

I am trying to use Tony's hidden menu items. I am able to capture the correct keys but I have a couple issues. I am not able to disable the MenuItem if it is invisible. If I make them visible (I'm OK with that if needed), I can disable the MenuItem so the key is no longer processed, but it is still captured, preventing the key from being used for normal data entry.

Is there any way to keep a MenuItem from capturing keystrokes that are assigned to it?

Thanks,

Paul

JTaylor

Would disabling MenuItem processing accomplish what you want?

   DialogProcOptions(MyDialog_Handle,MSG_MENUITEM,@FALSE)

I assume this can be turned on and off as desired???

Jim

PaulSamuelson

Disabling menu processing does not even stop it. It seems that by being defined in the dialog those keystrokes are captured.

Besides, I have other menu items I need to process.

Thanks,

Paul

td

WIL dialogs make menu items invisible by removing the item so the only style you can change that has an immediate effect when a menu is invisible is to make it visible again.  However, menu hotkeys are implemented by using the dialog's accelerator table which is a window resource handled by the OS for all Windows windows.  Removing a menu item does not disable its accelerator table entry precisely because leaving the table entry alone allows shortcut keys to exist in dialogs without requiring a visible menu item.



"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

I got so busy pontificating that I never got around to mentioning the most important part.  You can remove a menu's shortcut keys from a dialog's accelerator table by using the DialogControlSet function to change the stored text of the invisible menu item.   For example, the following will remove the enter key shortcut in the previously mentioned example:

Code (winbatch) Select
DialogControlSet(MyDialog_Handle,"cmi1_Enter",@dcTitle, '')
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

PaulSamuelson

Thanks!

I'm glad I checked back again. After reading your explanation of why it doesn't work, I was getting ready to change to a different approach. I happened to check back again and found your simple fix.

Thanks again,

Paul

td

This forum provides a "notify" button at the top and bottom of each topic.  You can use it to receive email notifications when new posts are made to the topic.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade