1
votes

I'm trying to replicate something similar to the Inkscape Zoom shortcuts shown below. Note that these Inkscape shortcuts work whether or not the number pad is used.

image

The first problem is that setting the shortcuts via the Object Inspector isn't possible, as there are no options for these keys on their own without modifier keys. I then tried setting the shortcuts at runtime as shown below. This shows the shortcut numbers in the menu, but the shortcuts don't work. I press the number key and nothing happens, whether or not the num pad is used (the menu items do work if I click them). The + and - shortcuts don't work, either.

Another problem is that the - shortcut is shown as '-' in the menu for some reason, and the + shortcut is shown as '=' because it's the same key. I have also tried using TextToShortcut(), but no luck.

Is this possible in FMX, or will I have to resort to using the function keys? I'd prefer to have consistency with Inkscape. I could handle the key presses in the Form's OnKeyDown event, but then how would I show the shortcut keys in the menu correctly (right hand side of the menu item)?

MenuItem1.ShortCut := vkEqual;
MenuItem2.ShortCut := vkMinus;
MenuItem3.ShortCut := vk1;
MenuItem4.ShortCut := vk2;
MenuItem5.ShortCut := vk5;
MenuItem6.ShortCut := vk3;
MenuItem7.ShortCut := vk4;
1
I think I've answered part of this myself. I can set the shortcut text in the menu item by using the tab character. MenuItem1.Text := MenuItem1.Text + #9 + '+'. I can then handle the shortcut execution in the FormKeyDown event. However, I'd still like to know if it's possible to set these shortcuts so that they work automatically. - XylemFlow
Have you tried vkAdd for + and vkSubtract for -? See Representing Keys and Shortcuts - Remy Lebeau
Yes, those represent the number pad keys, but they still don't work. I've now solved the issue as I described above. It seems like there's no alternative to handling the key events in FormKeyDown. - XylemFlow

1 Answers

0
votes

You can do it from source :

item1.ShortCut := 8299;

You get efect like on the picture

Becouse Shortcut of TmenuItem is of TShortCut and this is TShortCut = Low(Word)..High(Word);

its simple sum of key and Fkey :

Shift - 8192 

Ctrl - 16384

Alt - 32768


So we have 8299 = 
"numpad +" = 107 +
Shift = 8192

For using "+" and "Numeric +", use Action connected to Menu item:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Action1.Caption := 'Click'+#9+'+';
  Action1.SecondaryShortCuts.Add('Shift+=');
  Action1.SecondaryShortCuts.Add('Num +');
end;

best regards
Moskw@