sal1150
asked on
HOTKEY FOR MY APPLICATION
I like to make hotkey for my application.
My application is quiz game so I want "F9" to play and "F10" to stop it.
My application is quiz game so I want "F9" to play and "F10" to stop it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Other possibility is to set ShortCut property for MenuItem or Action if You are using Menus or AcionList
private
{ Private declarations }
Procedure WMHotkey( Var msg: TWMHotkey ); message WM_HOTKEY;
Procedure TForm1.WMHotkey( Var msg: TWMHotkey );
begin
if msg.hotkey = 1 Then
begin
//Start Game
ShowMessage('Start Game');
end;
if msg.hotkey = 2 Then
begin
//End Game
ShowMessage('End Game');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
If not RegisterHotkey( Form1.Handle, 1, MOD_ALT or MOD_SHIFT, VK_F9 ) Then
ShowMessage('Unable to assign F9 as hotkey.');
If not RegisterHotkey( Form1.Handle, 2, MOD_ALT or MOD_SHIFT, VK_F10 ) Then
ShowMessage('Unable to assign F10 as hotkey.');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotkey( Form1.Handle, 1 );
UnRegisterHotkey( Form1.Handle, 2 );
end;
SHane
You can also use Form's onShortCut event.
procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
case msg.CharCode of
120 : begin { F9 pressed }; Handled := true; end;
121 : begin { F10 pressed }; Handled := true; end;
end;
end;
procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
case msg.CharCode of
120 : begin { F9 pressed }; Handled := true; end;
121 : begin { F10 pressed }; Handled := true; end;
end;
end;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tray to applay Shane code but I get this error messge:-
[Error] Unit1.pas(111): Undeclared identifier: 'TWMHotkey'
[Error] Unit1.pas(111): Undeclared identifier: 'TWMHotkey'
ASKER
which unit shoud i use?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.