Say I have a form, with a menu bar on it. I have an item on the menu bar, a TMenuItem
, for which I can assign a shortcut key combo, say, for example Ctrl+I. But when I assign the ShortCut
property for the TMenuItem
, it seems to just change the visual appearance of the menu item to show the shortcut code rather than automatically listening for the short-cut key to be pressed and triggering my ActionManager code.
My google-fu seems to be failing today, I'm only finding articles about how to assign global-hot-keys for windows, not how to assign application-specific hot-keys that only work on the active form.
Can anyone outline for me the steps necessary to add a hot-key beyond just adding the shortcut property in the menu. I'm thinking somewhere I probably need to set the form to be listening for keyboard input and trap the keypress and respond to it? But I'm not exactly sure where or what the Delphi way to do that would be.
To assign a keyboard shortcut do the following: Begin keyboard shortcuts with CTRL or a function key. Press the TAB key repeatedly until the cursor is in the Press new shortcut key box. Press the combination of keys that you want to assign.
With HotKey You can define keyboard shortcuts to launch Applications or to open folders in Finder. Another way is to open the Apps by selecting them from the Status-Menu in Your Mac's menu bar. Another Feature: Show the content of the clipboard with one keyboard shortcut.
Thankfully, there is a keyboard shortcut that moves to the next line. Move the text cursor to where you want the new line to begin, press the Enter key, hold down the Shift key, and then press Enter again.
You seem to be using Actions (ActionManager), so assign your shortcut to the relevant Action instead. (Assigning the Action to the MenuItem will then assign the shortcut to the menu item, too.)
Consider the example of window handles are not provided for VCL message, for which we use WM_HOTKEY. This message is sent by registered window in Windows hotkey that allows the program to respond to it, even without the input focus:
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
// Declare a event handler
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
// Registering a hotkey Ctrl+Alt+F5
RegisterHotKey(Handle, 0, MOD_CONTROL or MOD_ALT, VK_F5);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// Unregisters a hotkey
UnRegisterHotKey(Handle, 0);
end;
procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
// This procedure is called when a window message WM_HOTKEY
inherited; // We give the form to process the message,
// if she already has its handler
Beep; // We perform additional actions
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With