Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delphi action manager shortcut for +,-, enter for actions

im working on delphi 7, and i have an applicaton where im using a action manager for creating actions and then assigning them shortcuts the shortcuts in action manager are already defined in the shortcut property..but i want to have a shortcut like

 1. ADD ,that is the + on the numpad
 2. Subtract key ,that is the - on the numpad
 3. divide key  , that is the / on the numpad.
 4. enter key

i tried assigning my own shortcut as subtract and ADD but it gives me this error message enter image description here

i also tried - but nothing is happening

my code to track the action

  var
      Action : TBasicAction;
      begin
        Action := Sender as TBasicAction;
       if (Action is TAction) and not TAction(Action).Enabled then   exit;
      case Action.tag of
        1                  :         ShowMessage('ADD + pressed');
        2                  :         ShowMessage ('divide / pressed');
        3                  :         ShowMessage ('subtract - pressed');
        4                  :         ShowMessage ('enter pressed');
      end;

   end;

i can use the normal

   **GetKeyState(VK_ADD) AND 128)=128;** OR **GetKeyState(VK_return) AND 128)=128;** 

to find it the keys are pressed in keypress or keydown event but i want to use the action manager shortcuts

like image 772
PresleyDias Avatar asked Nov 25 '25 11:11

PresleyDias


2 Answers

You can assign them at runtime:

Action1.ShortCut := menus.ShortCut(VK_ADD, []);
Action2.ShortCut := menus.ShortCut(VK_SUBTRACT, []);
like image 52
Sertac Akyuz Avatar answered Nov 28 '25 08:11

Sertac Akyuz


These keys have the following special names which can be assigned directly through the ShortCut property in the Object Inspector.

  • NUM ADD
  • NUM SUB
  • NUMMULT
  • /

I'm not sure about the numpad Enter key. I don't know if it has a special name or indeed if it can be distinguished from the normal Enter key using a shortcut.

Update

It turns out that the names for these keys vary from machine to machine. François points out that the names come from the GetKeyNameText Windows API function, for which the documentation points out:

The format of the key-name string depends on the current keyboard layout. The keyboard driver maintains a list of names in the form of character strings for keys with names longer than a single character. The key name is translated according to the layout of the currently installed keyboard, thus the function may give different results for different input locales.

For example, Sertac found that on his system, the names are NUM +, NUM - etc.

I generated the values by calling ShortcutToText and you could do the same to generate names appropriate for your system.

like image 33
David Heffernan Avatar answered Nov 28 '25 08:11

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!