| View previous topic :: View next topic |
| Author |
Message |
Dillonz Grandmaster Cheater
Reputation: 4
Joined: 20 Jan 2008 Posts: 758 Location: Under your bed
|
Posted: Sat Apr 18, 2009 6:59 pm Post subject: VB.NET Hotkeying |
|
|
| 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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Apr 18, 2009 7:19 pm Post subject: |
|
|
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 |
|
 |
Dillonz Grandmaster Cheater
Reputation: 4
Joined: 20 Jan 2008 Posts: 758 Location: Under your bed
|
Posted: Sat Apr 18, 2009 7:35 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Apr 18, 2009 9:58 pm Post subject: |
|
|
| 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 |
|
 |
FullyAwesome I post too much
Reputation: 0
Joined: 05 Apr 2007 Posts: 4438 Location: Land Down Under
|
Posted: Sun Apr 19, 2009 2:18 am Post subject: |
|
|
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 |
|
 |
Dillonz Grandmaster Cheater
Reputation: 4
Joined: 20 Jan 2008 Posts: 758 Location: Under your bed
|
Posted: Sun Apr 19, 2009 8:00 am Post subject: |
|
|
| 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 |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Sun Apr 19, 2009 8:50 am Post subject: |
|
|
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 |
|
 |
Dillonz Grandmaster Cheater
Reputation: 4
Joined: 20 Jan 2008 Posts: 758 Location: Under your bed
|
Posted: Sun Apr 19, 2009 2:55 pm Post subject: |
|
|
| Does anyone know what my new problem is?
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Apr 19, 2009 4:23 pm Post subject: |
|
|
| 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 |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Sun Apr 19, 2009 6:48 pm Post subject: |
|
|
| 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 |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sun Apr 19, 2009 10:56 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Apr 19, 2009 11:11 pm Post subject: |
|
|
| 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 |
|
 |
shayanomi Advanced Cheater
Reputation: 0
Joined: 01 Oct 2008 Posts: 52
|
|
| Back to top |
|
 |
Dillonz Grandmaster Cheater
Reputation: 4
Joined: 20 Jan 2008 Posts: 758 Location: Under your bed
|
Posted: Mon Apr 20, 2009 2:28 pm Post subject: |
|
|
| Your auto clicker isn't working for me.
|
|
| Back to top |
|
 |
|