HomerSexual Grandmaster Cheater Supreme Reputation: 5 Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Jul 24, 2007 11:03 am Post subject: RegisterHotKey , WMHotkey tutorial |
|
|
Welcome to the tutorial on RegisterHotkey using WMHotkey.
GetAsyncKeyState uses a timer, which uses more cpu power than a simple function w/o a timer.
Step 1) In the Type section you will see Private {private declations}.
So in the private declaration put this code
Code: | Procedure WMHotkey(var msg: TWMHotkey);
message WM_HOTKEY; |
This code just declares WMHotkey procedure.
Step 2) RegisterHotkey. In FormCreate procedure put this code.
Code: | if not RegisterHotKey(Handle, 1, MOD_CONTROL, VK_f12) then
begin
ShowMessage('Cant Assign CTRL+F12 as hotkey!');
end; |
This registers the HotKey to your window(handle), sets hotkey value to 1
(if your going to add another hotkey change this to 2,3,4 etc.) MOD_CONTROL is making sure the ctrl key is held down. VK_f12 is the key that must be pressed with ctrl.
You may add more HotKeys by repeating this code with different hotkey values.
Also if Ctrl + F12 is assigned already the ShowMessage will pop up.
Step 3) WMHotkey Function.
Code: | procedure TForm1.WMHotkey (Var msg: TWMHotkey);
begin
if msg.HotKey = 1 then begin
//do something
end;
end;
|
This procedure makes it so when you press the Hotkey assigned to 1, your actions are done.
3 Simple Steps.
No extra Cpu Power. _________________
|
|