Hey guys, this tutorial is leeched. I found an excellent website that contains it, and edited it. To see the original Tutorial, go here
This tutorial will explain how to make a hotkey function which works when the form is unfocused, hence, the name : Global Hotkey.
Firstly, you need to declare the GetAsyncKeyState API. To do this, type in this in the code:
[php]Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer[/php]So now, we'll want our program to check if the hotkeys are being pressed. We want it to check frequently so we can have an immediate reaction when the hotkey is pressed.
Add a timer. Double click on the Form. It should come up with the Form1.Load event.
Type this in:
[php]Timer1.enabled = true
Timer1.interval = 1[/php]
This sets the Timer's Interval to 1, and having it enabled. Now , we need the hotkey you want
pressed.
If you want 3 hotkeys to be pressed for your "whatever it is you need hotkeys for" to be
activated, then you'll need to declare 3 booleans in the Timer1.Tick Event.
For e.g. Ctrl+Alt+K. They can be called whatever you want.
[php]
Dim ctrl As Boolean
Dim alt As Boolean
Dim k As Boolean[/php]
When you have done that, you need to set their value.
We will use Ctrl-Alt-k again.
[php]ctrl = GetAsyncKeyState(Keys.ControlKey)
alt = GetAsyncKeyState(Keys.Menu)
k = GetAsyncKeyState(Keys.K)
[/php]
Now, an If Statement to check whether the keys have been pressed.
If ctrl And alt And k = True Then
'Put here the code that will initiate when the keys are pressed. E.g Timer2.Start
or Button1.Enabled
end if
So here is our final code:
[php]Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.enabled = true
Timer1.interval = 1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim ctrl As Boolean
Dim alt As Boolean
Dim k As Boolean
ctrl = GetAsyncKeyState(Keys.ControlKey)
alt = GetAsyncKeyState(Keys.Menu)
k = GetAsyncKeyState(Keys.K)
If ctrl And alt And k = True Then
'
'Put here the code that will initiate when the keys are pressed. E.g Timer2.Start
or Button1.Enabled
end if
End Class[/php]
Hope it worked for you! That was just an example. You can have as many
or as short hotkeys as you want. Just edit the sample code above.
E.g. if you wanted 2 hotkeys:
[php]Dim blaa As Boolean
Dim waaa As Boolean
blaa= GetAsyncKeyState(Keys.B)
waaa = GetAsyncKeyState(Keys.W)
if blaa and waaa = true then
'Here is the code that runs again'
end if
[/php]
*A Handy Few Notes from CodingIlliterate
Any Button on your keyboard like Control, Shift etc. is
(Keys.ControlKey)
not
(Keys.Control)
I also spent lots of time searching for the Alt Key.
The Alt Key is
(Keys.Menu)
Thanks for Reading! Hope it helped and if you liked it, press thanks!
Last edited by Invidus; 03-28-2010 at 08:40 PM.
Thanks for sharing, Looks good
Thanks NextGen! I hope it helps those who do not know how to use hotkeys, and those who do, to learn about Global Hotkeys.
ima leech this from u >=) jk thanks it will make spammers and tappers 10+ easyer
Hhehe. NextGen can you put this in your list of TuTs?? Pweeze =D
I will add it soon
ok thanks nextgen
Wasn't this posted multiple times?
Thanks for sharing buddy. Very helpful
Yea seen it a few times on mpgh, thanks for sharing though
=P. Thanks Blubb. Anyway i didn't leech it from previous posters. I just found a good website and decided it to share info with yooh guys!
I'm thinking about doing an advanced trainer tutorial but idk
For MWF2? /too short
generally for all games