viewpoint-particle

Author Topic: Key Equivalents within Dialog  (Read 82 times)

PaulSamuelson

  • Newbie
  • *
  • Posts: 34
Key Equivalents within Dialog
« 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

JTaylor

  • Pundit
  • *****
  • Posts: 927
    • Data & Stuff Inc.
Re: Key Equivalents within Dialog
« Reply #1 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

PaulSamuelson

  • Newbie
  • *
  • Posts: 34
Re: Key Equivalents within Dialog
« Reply #2 on: November 27, 2018, 10:30:49 am »
Thanks Jim (and Tony). I think that will help.

Paul

PaulSamuelson

  • Newbie
  • *
  • Posts: 34
Re: Key Equivalents within Dialog
« Reply #3 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

JTaylor

  • Pundit
  • *****
  • Posts: 927
    • Data & Stuff Inc.
Re: Key Equivalents within Dialog
« Reply #4 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

PaulSamuelson

  • Newbie
  • *
  • Posts: 34
Re: Key Equivalents within Dialog
« Reply #5 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

td

  • Tech Support
  • *****
  • Posts: 2653
    • WinBatch
Re: Key Equivalents within Dialog
« Reply #6 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.



"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


td

  • Tech Support
  • *****
  • Posts: 2653
    • WinBatch
Re: Key Equivalents within Dialog
« Reply #7 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
DialogControlSet(MyDialog_Handle,"cmi1_Enter",@dcTitle, '')
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


PaulSamuelson

  • Newbie
  • *
  • Posts: 34
Re: Key Equivalents within Dialog
« Reply #8 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