| View previous topic :: View next topic |
| Author |
Message |
haxor5354 Master Cheater
Reputation: 0
Joined: 11 Jan 2008 Posts: 306 Location: Toronto
|
Posted: Wed Jun 04, 2008 6:22 am Post subject: VB 2008 HotKeys question |
|
|
how do I make hot keys to click button 1 and button 2. it has to work even if it not focused on form1.
+rep if good answer
_________________
My Rig
MoBo: Asus P5QPL-AM
Cpu: Intel Core 2 Quad Q8200
Ram: Kingston 2x2GB DDR2 800
GFX: Asus ENGTS250 DK
HDD: 500GB WD Caviar Green
Mon: LG Flatron W2243T 1080p |
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Wed Jun 04, 2008 6:49 am Post subject: |
|
|
Check out the RegisterHotKey API. It allows you to use it when the form isn't focused. You could make the hotkey run the code instead of the button, or simulate a click with the sub declaration.
For example, when you click button1, it also clicks button2:
| Code: | | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click |
Notice the Handles Button1.Click, Button2.Click part.
|
|
| Back to top |
|
 |
sumnewdude Expert Cheater
Reputation: 0
Joined: 23 May 2007 Posts: 181 Location: Where you least expect me.
|
Posted: Wed Jun 04, 2008 10:55 am Post subject: |
|
|
Well I use this API
| Code: | | Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Short |
Then all you need to do is check to see if it changed but using a If Then, like so
| Code: | If GetAsyncKeyState(112) Then
AdjustToolStripMenuItem.PerformClick()
end if |
That is checking if F1 was pressed. Also I think you have to put it on a timer.
_________________
.erutangis ruoy ni siht esu neht ,sdrawkcab siht daer ot hguone trams erew uoy fI |
|
| Back to top |
|
 |
haxor5354 Master Cheater
Reputation: 0
Joined: 11 Jan 2008 Posts: 306 Location: Toronto
|
Posted: Wed Jun 04, 2008 4:22 pm Post subject: |
|
|
can you give me an example please?
_________________
My Rig
MoBo: Asus P5QPL-AM
Cpu: Intel Core 2 Quad Q8200
Ram: Kingston 2x2GB DDR2 800
GFX: Asus ENGTS250 DK
HDD: 500GB WD Caviar Green
Mon: LG Flatron W2243T 1080p |
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
|
| Back to top |
|
 |
haxor5354 Master Cheater
Reputation: 0
Joined: 11 Jan 2008 Posts: 306 Location: Toronto
|
Posted: Wed Jun 04, 2008 5:21 pm Post subject: |
|
|
too complicated >.<
can u make me a sample source code?
_________________
My Rig
MoBo: Asus P5QPL-AM
Cpu: Intel Core 2 Quad Q8200
Ram: Kingston 2x2GB DDR2 800
GFX: Asus ENGTS250 DK
HDD: 500GB WD Caviar Green
Mon: LG Flatron W2243T 1080p |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Wed Jun 04, 2008 5:30 pm Post subject: |
|
|
| haxor5354 wrote: | too complicated >.<
can u make me a sample source code? |
Stop begging. You aren't going to learn with people just handing you things. Take the time to learn it yourself.
_________________
- Retired. |
|
| Back to top |
|
 |
AndrewMan Grandmaster Cheater Supreme
Reputation: 0
Joined: 01 Aug 2007 Posts: 1257
|
Posted: Wed Jun 04, 2008 9:32 pm Post subject: |
|
|
| Wiccaan wrote: | | haxor5354 wrote: | too complicated >.<
can u make me a sample source code? |
Stop begging. You aren't going to learn with people just handing you things. Take the time to learn it yourself. |
This is true. Only ask a question when you are truly stumbled and have tried all your options and nothing works.
_________________
|
|
| Back to top |
|
 |
haxor5354 Master Cheater
Reputation: 0
Joined: 11 Jan 2008 Posts: 306 Location: Toronto
|
Posted: Thu Jun 05, 2008 6:24 am Post subject: |
|
|
| Code: | rivate Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Integer = &H312
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Me.Handle.ToInt32, 0, 0, System.Windows.Forms.Keys.F11)'edit this for the hotkey you want
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
'code for if they press hotkey here
Else
End If
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
UnregisterHotKey(Me.Handle.ToInt32, 0)
End Sub |
okaaaaaaay. I only got 1 hotkey working but i need 2 hot keys for start and stop what should I do?
_________________
My Rig
MoBo: Asus P5QPL-AM
Cpu: Intel Core 2 Quad Q8200
Ram: Kingston 2x2GB DDR2 800
GFX: Asus ENGTS250 DK
HDD: 500GB WD Caviar Green
Mon: LG Flatron W2243T 1080p |
|
| Back to top |
|
 |
|