WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: PaulSamuelson on November 27, 2018, 07:45:07 AM

Title: Key Equivalents within Dialog
Post by: PaulSamuelson on November 27, 2018, 07:45:07 AM
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
Title: Re: Key Equivalents within Dialog
Post by: JTaylor on November 27, 2018, 09:31:23 AM
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
Title: Re: Key Equivalents within Dialog
Post by: PaulSamuelson on November 27, 2018, 10:30:49 AM
Thanks Jim (and Tony). I think that will help.

Paul
Title: Re: Key Equivalents within Dialog
Post by: PaulSamuelson on November 28, 2018, 10:07:30 AM
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
Title: Re: Key Equivalents within Dialog
Post by: JTaylor on November 28, 2018, 10:13:33 AM
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
Title: Re: Key Equivalents within Dialog
Post by: PaulSamuelson on November 28, 2018, 10:25:32 AM
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
Title: Re: Key Equivalents within Dialog
Post by: td on November 28, 2018, 01:39:38 PM
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.



Title: Re: Key Equivalents within Dialog
Post by: td on November 28, 2018, 02:26:28 PM
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, '')
Title: Re: Key Equivalents within Dialog
Post by: PaulSamuelson on November 29, 2018, 06:34:27 AM
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
Title: Re: Key Equivalents within Dialog
Post by: td on December 17, 2018, 06:56:39 AM
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.