Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[DELPHI]RegisterHotKey API

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
gunminiho
Expert Cheater
Reputation: 0

Joined: 15 Dec 2008
Posts: 144
Location: peru

PostPosted: Fri Jun 19, 2009 11:17 pm    Post subject: [DELPHI]RegisterHotKey API Reply with quote

well hmm i wanna know the use of this WINAPI named: RegisterHotKey wich in delphi is declared like this:

Code:
function RegisterHotKey (hwnd : Integer;
    id : Integer;
    fsModifiers : Integer;
    vk : Integer) : Integer;
    stdcall; external 'user32' name 'RegisterHotKey'


let's say that im making any hack SuperTubi for example and i wanna replace GetAsyncKeyState() for RegisterHotKey():

Library SuperTubi;

var

var
Pid: Integer;
Pidhandle: integer;
Address: Cardinal
NewValue: Integer;
Data: Integer;
Written: Cardinal;

...

...

Function RegisterHotKeys: Integer;

var
Counter:Integer;
begin
Counter:=1;
If RegisterHotKey(....) <> 0 then begin Counter: = Counter+1;
RegisterHotKey(....) <> 0 then begin Counter: = Counter+1;
RegisterHotKey(....) <> 0 then begin Counter: = Counter+1;
RegisterHotKey(....) <> 0 then begin Counter: = Counter+1;
If (Counter =! 5 ) then
begin
ShowMessage('OMFG not all HotKeys are registered, i will close ur hack O.o');
ExitThread(MSThread);
end;
end;

Procedure SuperTubi;
begin
while true do
begin
If GetAsyncKeyState() <> 0 then
begin
Address := $04000000;
NewValue := 666;
Data := 4;

if GetID(process,Pid) then
begin
Pidhandle := OpenProcess(PROCESS_ALL_ACCESS,False,Pid);
WriteProcessMemory(Pidhandle, Pointer(Address), @NewValue, Data, Written);
closehandle(Pidhandle);

Pidhandle := OpenProcess(PROCESS_ALL_ACCESS,False,Pid);
WriteProcessMemory(Pidhandle, Pointer(Address), @NewValue, Data, Written);
closehandle(Pidhandle);

end;
end;

hwnd = Pid ?
id = 100?
fsModifiers = it could be something like: HexToInt(11); // 11=Control Key's hex value
vk = vk_f1

can i?

after that i saw in Kitterz Source Trainer he uses: UnregisterHotKey

Code:
function UnregisterHotKey (hwnd : Integer;
    id : Integer) : Integer;
    stdcall; external 'user32' name 'UnregisterHotKey'


when do i register and when do i unregister a hotkey? and where to implement it?

can i make a procedure that when i inject my dll it automatic run it?
something like:

Code:
Library SuperTubi;

var
  Pid: Integer;
  Pidhandle: integer;
  Address: Cardinal
  NewValue: Integer;
  Data: Integer;
  Written: Cardinal;

...

...

Procedure SuperTubi;
while true do
begin
If GetAsyncKeyState() <> 0  then
begin
Address := $04000000;
NewValue := 666;
Data := 4;

if GetID(process,Pid) then
begin
Pidhandle := OpenProcess(PROCESS_ALL_ACCESS,False,Pid);
WriteProcessMemory(Pidhandle, Pointer(Address), @NewValue, Data, Written);
closehandle(Pidhandle);

Pidhandle := OpenProcess(PROCESS_ALL_ACCESS,False,Pid);
WriteProcessMemory(Pidhandle, Pointer(Address), @NewValue, Data, Written);
closehandle(Pidhandle);

end;
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jun 20, 2009 9:33 am    Post subject: Reply with quote

RegisterHotKey would be implimented in the start of your library as its loaded or whenever you want to use them. UnregisterHotKey will be called at the end of your library, or when its being freed, or even when you don't need to use them anymore. The key difference between GetAsyncKeyState and RegisterHotKey is that RegisterHotKey no longer is called over and over again, it is implimented within the message cycle and you must filter WM_HOTKEY messages as to when keys are pressed.
_________________
Back to top
View user's profile Send private message
gunminiho
Expert Cheater
Reputation: 0

Joined: 15 Dec 2008
Posts: 144
Location: peru

PostPosted: Sun Jun 21, 2009 12:26 am    Post subject: Reply with quote

excuse my english(spanish as first language) :S but i didnt understand u Sad, could you please make a lil example or better use common words Very Happy

also...

hwnd = HandleWindows?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Jun 21, 2009 9:33 am    Post subject: Reply with quote

With RegisterHotKey you must have a window to supply the HWND value (unless you provide a hook to filter out WM_HOTKEY messages...)

HWND generally means Handle to a Window.

_________________
Back to top
View user's profile Send private message
gunminiho
Expert Cheater
Reputation: 0

Joined: 15 Dec 2008
Posts: 144
Location: peru

PostPosted: Sun Jun 21, 2009 11:12 am    Post subject: Reply with quote

hmmm sounds intresting well so i get HWND with:

Function GetHwnd(var WindowsName:String): Integer;
var
hwnd:Integer;
begin
hwnd:= FindWindows(WindowsName,nil);
Result:= hwnd;


so in windows name i can put: "M-aplestory" or "Rakion" or "Audition" or any name of my windows?

also i dont get it, how to use it, i mean i can register it maybe but? after that how do i set my HotKey to work? i mean i was doing this with GetAsyncKeyState:

while true do
begin
If GetAsyncKeyState(vk_f1) <> 0 then
begin
<code>
end;
end;
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Jun 21, 2009 11:37 am    Post subject: Reply with quote

You would have to create a window or hook the windows messages.

As when you call RegisterHotKey the system tracks keystrokes for that specific hotkey then sends the window that registered that hotkey a WM_HOTKEY message that includes information about that hotkey.

If you havent dealt with messages before you should probably learn the basic idea about them before you try using it.

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites