6

It might seem natural to use Ctrl + +, Ctrl + -, and Ctrl + 0 as shortcuts for an application's zoom in, zoom out, and restore default zoom (typically 100 %) actions. Now, in Delphi, I am able to assign Ctrl + + and Ctrl + 0 as shortcuts. The former, though, requires that the plus sign of the main part of the keyboard is used; the plus sign of the numerical keypad cannot be used.

Problem arises, however, when I want to assign Ctrl + - as a shortcut. It simply doesn't work. If I assign "Ctrl+-" in the IDE, the value stored in the ShortCut property is 16495. If we subtract ssCtrl from this, we obtain 111. A work-around, one would believe, would be to assign ShortCut := 45 + ssCtrl, or, equivalently, ShortCut := Menus.ShortCut(45, [ssCtrl]), because ord('-') = 45. But that doesn't work.

However, I have found a working solution: ShortCut := 189 + ssCtrl. I choose 189 because that is the number I receive when I depress the "-" key and listen to the KeyDown event.

So, why am I not happy with this? Well, I am afraid that the constant 189 only is valid on Swedish keyboards. I have tried to read about this, and, as usual, the MSDN documentation is rather clear, but then, who knows how Delphi handles things.

2
  • Tip: add an alias for Ctrl+= for zoom in, otherwise you have to use Ctrl+Shift++ on keyboards without numeric keypads.
    – Douglas
    Aug 28, 2010 at 23:49
  • @Douglas: On my keyboard, I insert a plus sign by pressing the + key (no shift or ctrl+shift) right above "P" and "Å" (yes, Swedish keyboards do look like that - 99.se/attachments/powerbook-macbook-pro/…). This is also my issue: keys aren't the same on different keyboards. Aug 29, 2010 at 0:51

3 Answers 3

6

The key code 189 is VK_OEM_MINUS in Windows.pas, so your solution isn't just for Swedes.

1
  • Thank you very much. This was exactly what I wanted to hear! Aug 29, 2010 at 0:53
1

the correct to use menu shortcut on the numeric pad is
CtrlNum + for the [+]
CtrlNum - for the [-]

there is a space between Num + and Num -

0

I'm not sure why you're getting 16495 for Ctrl + -. When I add that shortcut to an action, it gives me 16573, and it does show up on the menu as Ctrl + -, and that shortcut does work.

However, you are correct that Menus.ShortCut(ord('-', [ssCtrl]) does not work. It gives the value 16429 and shows up on the menu as Ctrl + Ins, and Ctrl + Ins works as the shortcut.

Maybe this is a problem with Delphi 2009 and later since they added Unicode.

3
  • The Word type-cast is equivalent to the Ord function that he already tried. Aug 28, 2010 at 23:26
  • Yes, but he doesn't want to hardcode the "45". Whereas this allows the character he wants. I'm not sure why he says it doesn't work on his machine. Either the "45" or the Word('-') both seem to work for me.
    – lkessler
    Aug 28, 2010 at 23:34
  • Oh, now I see his problem. The ShortCut function doesn't work. I'll have to change my answer.
    – lkessler
    Aug 28, 2010 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.