RaelB
RaelB

Reputation: 3481

How can I set a TAction's Shortcut to Ctrl + Numpad 0?

I've tried this:

actZoomReset.ShortCut := TextToShortCut('Ctrl+Num 0');

But this does nothing (ShortCut = 0).

EDIT:

If I try to set the value in the IDE (Ctrl+Num 0), directly in the ShortCut property, I get the error: "Invalid Property Value". If I double click on the Shortcut property, and then press "Ctrl" and "Numkey 0", it shows "Ctrl+Num 0" in the hotkey edit, and when I press enter, it shows "Ctrl+Ins" in the ShortCut field.

Actually

actZoomReset.ShortCut := TextToShortCut('Ctrl+Ins');

Will work. My question then becomes, will this work on other keyboards, or is this a quirk of my own keyboard? I'm using a Logitech G213. The numpad 0 has "Ins" under it.

I'm using Delphi 10.2 on Windows 10

Upvotes: 2

Views: 1370

Answers (1)

Andreas Rejbrand
Andreas Rejbrand

Reputation: 109158

The simplest way is to set the action's short cut at design time using the Object Inspector:

Screenshot of the Object Inspector showing the ShortCut property set to Ctrl+Num 0.

But if you need to set this property programmatically, you can do

actZoomReset.ShortCut := ShortCut(VK_NUMPAD0, [ssCtrl])

(Typically, there is no need to adjust an action's non-state properties at runtime. The state properties are Visible, Enabled, and Checked.)

Regarding your edit:

It sounds like you have accidentally turned off NUM LOCK. When NUM LOCK is ON (the default), the 0/INS key means 0. When NUM LOCK is off, it means INS.

To turn on NUM LOCK, press the key in the red circle. When NUM LOCK is on, the LED in the green circle will be on.

Image of the OP's keyboard with the NUM LOCK key and its associated LED highlighted.

Upvotes: 5

Related Questions