Pause/Break as a Keyboard ShortCut (Win32, *Possibly* Delphi-specific)
Is it not possible to use the Pause/Break key in keyboard shortcuts?
I know I can respond to the Pause/Break key, e.g.
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_PAUSE then
ShowMessage('VK_PAUSE pressed');
end;
However, I am unable to respond to the Pause/Break key using开发者_开发问答 the TShortCut
properties, e.g. in menu items and action lists. The Object Inspector lets me enter Pause, Shift + Pause, Ctrl + Pause, Alt + Pause, Ctrl + Shift + Pause etc. so it clearly recognizes the Pause key. But when I run the application, the menu item/action is not triggered on the specified shortcut. Is there a known workaround?
With D2007, a quick workaround seems to be assigning it in the run-time;
Action1.ShortCut := VK_PAUSE;
For some reason if assigned in design-time, VK_PAUSE (19) seems to mutate to VK_NUMLOCK (144).
When a shortcut is assigned in design time the IDE has to convert a string to a shortcut. The problem is
TextToShortCut('Pause');
returns 144 instead of 19. Though I'm not sure I believe the error is with Delphi; With 'Pause', retrieving a shortcut finds its way to menus.GetSpecialName
, I think it should not.
On another note, while the workaround mentioned above works with 'Alt' and 'Shift' modifiers, it doesn't work with the 'Ctrl' modifier. The reason is, the OS assings 'Ctrl+Break' processing a special code: VK_CANCEL
. To use 'Ctrl+Pause' as a shortcut one have to code;
Action1.ShortCut := menus.Shortcut(VK_CANCEL, [ssCtrl]);
精彩评论