Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 251
Andreas Rejbrand Avatar asked Dec 16 '22 23:12

Andreas Rejbrand


1 Answers

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]);
like image 139
Sertac Akyuz Avatar answered Jan 15 '23 13:01

Sertac Akyuz