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 


VB.NET Hotkeying

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

Joined: 20 Jan 2008
Posts: 758
Location: Under your bed

PostPosted: Sat Apr 18, 2009 6:59 pm    Post subject: VB.NET Hotkeying Reply with quote

Nothing seems to work. I'm making an auto clicker and I need hotkeys to activate it. I've looked at like 10 tutorials and none of them worked.
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Apr 18, 2009 7:19 pm    Post subject: Reply with quote

GetAsyncKeyState(), and just spawn a thread / use a timer to check every so often.

or

RegisterHotKey(), and respond to WM_HOTKEY. Override WndProc and handle the message.
Back to top
View user's profile Send private message
Dillonz
Grandmaster Cheater
Reputation: 4

Joined: 20 Jan 2008
Posts: 758
Location: Under your bed

PostPosted: Sat Apr 18, 2009 7:35 pm    Post subject: Reply with quote

I've been using the GetAsyncKeyState, I think I'm going to try the RegisterHotKey.
Edit: It's confusing I don't really understand it lol.
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Apr 18, 2009 9:58 pm    Post subject: Reply with quote

Teknological wrote:
I've been using the GetAsyncKeyState, I think I'm going to try the RegisterHotKey.
Edit: It's confusing I don't really understand it lol.


1. Show me what you were doing with GetAsyncKeyState; you were running it off a timer / thread, right?

2. RegisterHotKey is simple, you just respond to WM_HOTKEY

http://msdn.microsoft.com/en-us/library/ms646279(VS.85).aspx

Code:
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
     Const WM_HOTKEY As Integer = &H312
   
     Select Case m.Msg
         Case WM_HOTKEY
             If m.WParam = Keys.Something Then
                 'do something incredible.
             End If
             Exit Select
         Case Else
             MyBase.WndProc(m)
             Exit Select
     End Select
End Sub
Back to top
View user's profile Send private message
FullyAwesome
I post too much
Reputation: 0

Joined: 05 Apr 2007
Posts: 4438
Location: Land Down Under

PostPosted: Sun Apr 19, 2009 2:18 am    Post subject: Reply with quote

here's a little more in-depth of what slovach's telling you to do with RegisterHotkey.

first you want to declare:

Code:
Private Const WM_HOTKEY As Integer = &H312
    Public Declare Auto Function RegisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
    Public Declare Auto Function UnregisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer) As Boolean


in your form loading event, add

Code:
RegisterHotKey(Me.Handle, 1020, 0, Keys.F1)
RegisterHotKey(Me.Handle, 1040, 0, Keys.F2)


you don't have to have f1 or f2, change that part for whatever hotkeys you want and add more or less. make sure when you add more, the id (1020, 1040 part) is different.

then when you respond to wm_hotkey, add this sub:

Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        MyBase.WndProc(m)
        If (m.Msg = WM_HOTKEY) Then
            Select Case m.WParam
                      Case 1020 'id of hotkey F1
                              'What to do when F1 is pressed.
                      Case 1040
                              'And so on
            End Select
        End If
    End Sub


then during your form's closing event, unregister the hotkeys with their ids:

Code:
UnregisterHotKey(Me.Handle, 1020)
UnregisterHotKey(Me.Handle, 1040)

_________________
Back to top
View user's profile Send private message MSN Messenger
Dillonz
Grandmaster Cheater
Reputation: 4

Joined: 20 Jan 2008
Posts: 758
Location: Under your bed

PostPosted: Sun Apr 19, 2009 8:00 am    Post subject: Reply with quote

K thanks but now I go only one problem. I'm using F12 to stop the auto clicker but it's not doing anything.
Back to top
View user's profile Send private message MSN Messenger
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Sun Apr 19, 2009 8:50 am    Post subject: Reply with quote

I've seen those kinds of answers before, but I've always wanted to know how to have some generic hotkey-making code.. or more specifically, how can you make the hotkey being pressed act like an event?
i.e. rather than doing
Code:
Select Case m.WParam
    Case 1020 'id of hotkey F1
        'What to do when F1 is pressed.
    Case 1040
        'And so on
End Select
it will call a function or sub straight away..
Basically I'm asking how to make it so you can dynamically change the code that will be run when the hotkey is pressed as I want to write a function that assigns a hotkey to another function or sub, and therefore separate the hotkey code from the main project and have it like a class or module..
Back to top
View user's profile Send private message
Dillonz
Grandmaster Cheater
Reputation: 4

Joined: 20 Jan 2008
Posts: 758
Location: Under your bed

PostPosted: Sun Apr 19, 2009 2:55 pm    Post subject: Reply with quote

Does anyone know what my new problem is?
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Apr 19, 2009 4:23 pm    Post subject: Reply with quote

shhac wrote:
I've seen those kinds of answers before, but I've always wanted to know how to have some generic hotkey-making code.. or more specifically, how can you make the hotkey being pressed act like an event?
i.e. rather than doing
Code:
Select Case m.WParam
    Case 1020 'id of hotkey F1
        'What to do when F1 is pressed.
    Case 1040
        'And so on
End Select
it will call a function or sub straight away..
Basically I'm asking how to make it so you can dynamically change the code that will be run when the hotkey is pressed as I want to write a function that assigns a hotkey to another function or sub, and therefore separate the hotkey code from the main project and have it like a class or module..


With RegisterHotkey you must respond to the WM_HOTKEY notification.

http://msdn.microsoft.com/en-us/library/ms646279(VS.85).aspx
Quote:
wParam
Specifies the identifier of the hot key that generated the message. If the message was generated by a system-defined hot key, this parameter will be one of the following values.


So yeah. You could run GetAsyncKeyState in the back as well if you really didn't want to use RegisterHotkey for some reason. You won't have to respond to anything then, just check the return.
Back to top
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Sun Apr 19, 2009 6:48 pm    Post subject: Reply with quote

slovach wrote:
shhac wrote:
I've seen those kinds of answers before, but I've always wanted to know how to have some generic hotkey-making code.. or more specifically, how can you make the hotkey being pressed act like an event?
i.e. rather than doing
Code:
Select Case m.WParam
    Case 1020 'id of hotkey F1
        'What to do when F1 is pressed.
    Case 1040
        'And so on
End Select
it will call a function or sub straight away..
Basically I'm asking how to make it so you can dynamically change the code that will be run when the hotkey is pressed as I want to write a function that assigns a hotkey to another function or sub, and therefore separate the hotkey code from the main project and have it like a class or module..


With RegisterHotkey you must respond to the WM_HOTKEY notification.

http://msdn.microsoft.com/en-us/library/ms646279(VS.85).aspx
Quote:
wParam
Specifies the identifier of the hot key that generated the message. If the message was generated by a system-defined hot key, this parameter will be one of the following values.


So yeah. You could run GetAsyncKeyState in the back as well if you really didn't want to use RegisterHotkey for some reason. You won't have to respond to anything then, just check the return.
I think you misunderstood me, I'm asking how to write a function that can be used to make hotkeys like this
Code:
NewHotKey = MakeHotKey(KeyCombination, AnotherFunctionOrSubWhichWillBeRunWhenHotkeyPressed)
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Sun Apr 19, 2009 10:56 pm    Post subject: Reply with quote

he said yes if you use GetAsyncKeyState

but if you register a hotkey i dont think you can do it because you have to put it in your forms events

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

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Apr 19, 2009 11:11 pm    Post subject: Reply with quote

shhac wrote:
slovach wrote:
shhac wrote:
I've seen those kinds of answers before, but I've always wanted to know how to have some generic hotkey-making code.. or more specifically, how can you make the hotkey being pressed act like an event?
i.e. rather than doing
Code:
Select Case m.WParam
    Case 1020 'id of hotkey F1
        'What to do when F1 is pressed.
    Case 1040
        'And so on
End Select
it will call a function or sub straight away..
Basically I'm asking how to make it so you can dynamically change the code that will be run when the hotkey is pressed as I want to write a function that assigns a hotkey to another function or sub, and therefore separate the hotkey code from the main project and have it like a class or module..


With RegisterHotkey you must respond to the WM_HOTKEY notification.

http://msdn.microsoft.com/en-us/library/ms646279(VS.85).aspx
Quote:
wParam
Specifies the identifier of the hot key that generated the message. If the message was generated by a system-defined hot key, this parameter will be one of the following values.


So yeah. You could run GetAsyncKeyState in the back as well if you really didn't want to use RegisterHotkey for some reason. You won't have to respond to anything then, just check the return.
I think you misunderstood me, I'm asking how to write a function that can be used to make hotkeys like this
Code:
NewHotKey = MakeHotKey(KeyCombination, AnotherFunctionOrSubWhichWillBeRunWhenHotkeyPressed)


Yeah, you can use a Hotkey control to easily get the key combination. I don't know how .NET handles them, but under Win32 you can just send it a WM_GETHOTKEY, then use that.
Back to top
View user's profile Send private message
shayanomi
Advanced Cheater
Reputation: 0

Joined: 01 Oct 2008
Posts: 52

PostPosted: Sun Apr 19, 2009 11:38 pm    Post subject: Reply with quote

My complete source for my autoclicker: Twisted Evil It has hotkeys too
(f11 to start and f12 to stop) Very Happy

Rep if I helped, tell me if you didn't approve



The Extension 'zip' was deactivated by an board admin, therefore this Attachment is not displayed.

Back to top
View user's profile Send private message
Dillonz
Grandmaster Cheater
Reputation: 4

Joined: 20 Jan 2008
Posts: 758
Location: Under your bed

PostPosted: Mon Apr 20, 2009 2:28 pm    Post subject: Reply with quote

Your auto clicker isn't working for me.
Back to top
View user's profile Send private message MSN Messenger
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