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 


Quick question

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

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Thu Jun 26, 2008 12:22 am    Post subject: Quick question Reply with quote

For hotkeys, where do I put them?

Example:

Code:
If keys.A Then
      Button1.Visible = True
End if


Where do I put this? Not in the form load...

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Jun 26, 2008 12:53 am    Post subject: Reply with quote

You get to venture into the wonderful world of Win32 API / Windows messages for this one.

If you were going to do it like that, you'd need to throw that on the WM_KEYDOWN message for your window. To do that in .NET, you need to override WndProc. This will only work if your window is the active one anyway, so if you're looking for the hotkeys to work at any time, you're better off with...

RegisterHotKey or
GetAsyncKeyState
Back to top
View user's profile Send private message
Typhoon808
Expert Cheater
Reputation: 0

Joined: 27 Mar 2008
Posts: 175
Location: Wales

PostPosted: Thu Jun 26, 2008 6:36 am    Post subject: Reply with quote

You would put that in the Form1_KeyDown event. However, it is best to use an API such as RegisterHotKey as slovach said.
Back to top
View user's profile Send private message
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Thu Jun 26, 2008 9:27 am    Post subject: Reply with quote

Typhoon808 wrote:
You would put that in the Form1_KeyDown event. However, it is best to use an API such as RegisterHotKey as slovach said.


thanks guys. Very Happy

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Jun 26, 2008 7:05 pm    Post subject: Reply with quote

Typhoon808 wrote:
You would put that in the Form1_KeyDown event. However, it is best to use an API such as RegisterHotKey as slovach said.


That would only work if the form itself has focus then. Typically people would want the hotkey to work with the window not in focus and such as well. Which would put the API in better suite for that purpose.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Jun 26, 2008 7:13 pm    Post subject: Reply with quote

Typhoon808 wrote:
You would put that in the Form1_KeyDown event. However, it is best to use an API such as RegisterHotKey as slovach said.


Oh man I completely forgot about form events.

Just remember, your form needs to be in focus to get the messages.
Back to top
View user's profile Send private message
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Thu Jun 26, 2008 8:40 pm    Post subject: Reply with quote

I put my form in focus, but this whole RegisterHotKey thing is so confusing.

I have to import some sort of DLL, than call GlobalAddAtom?

Been Googling quite a bit, there seems that you must do so much work just to get some simple Hotkey working.

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jun 27, 2008 9:34 pm    Post subject: Reply with quote

You don't have to do all that, it is just the proper method of doing it. If it's too confusing, you can always just use GetAsyncKeyState.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Jun 27, 2008 10:34 pm    Post subject: Reply with quote

AndrewMan wrote:
I put my form in focus, but this whole RegisterHotKey thing is so confusing.

I have to import some sort of DLL, than call GlobalAddAtom?

Been Googling quite a bit, there seems that you must do so much work just to get some simple Hotkey working.


pinvoke.net + msdn

declare the pinvoke signature
Code:
<DllImport("user32.dll")> _
Public Shared Function RegisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer, _
    ByVal fsModifier As Integer, ByVal vk As Integer) As Integer
End Function


what msdn says.
Code:
BOOL RegisterHotKey(   
    HWND hWnd,
    int id,
    UINT fsModifiers,
    UINT vk


Get the handle of your window: me.Handle();
Set an id, say... 1
No modifiers, 0
Finally use the keys class to get a virtual key.

With your hotkey registered, you can respond to it on WM_HOTKEY by overriding WndProc. When you're done, just UnregisterHotkey.

I'm pulling this part out of my ass as how to actually do it, but it should be close enough

Code:
int WM_HOTKEY = 0x312;

Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
            Case WM_HOTKEY Then
m.GetLParam(I'M TOO LAZY TO LOOK UP HOW IT WORKS, so you can do it)
End If
End Sub

Or you can just throw GetAsyncKeyState into a thread, loop, timer, whatever.

The whole process is just made needlessly more complicated in managed code IMO.
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