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 


[Visual Basics 6.0] Hotkeying (Question)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Mon Oct 29, 2007 9:52 pm    Post subject: [Visual Basics 6.0] Hotkeying (Question) Reply with quote

Could somebody please give me the code that you enter in the "view code" screen to Hotkey an Auto-Clicker
Thanks +Rep
(If its not possible just say so but i remember theres a Function to do it)

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

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Oct 29, 2007 10:27 pm    Post subject: Reply with quote

RegisterHotKey

http://msdn2.microsoft.com/en-us/library/ms911003.aspx
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: Tue Oct 30, 2007 12:00 am    Post subject: Reply with quote

You can also use GetAsyncKeyState() which is used inside a timer:

Code:
Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Timer1_Timer()

    If GetAsyncKeyState(vbKeyF12) Then
        MsgBox "F12 was pressed!", vbInformation, "Info"
    End If

End Sub

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Tue Oct 30, 2007 4:29 am    Post subject: Reply with quote

Wiccaan wrote:
You can also use GetAsyncKeyState() which is used inside a timer:

Code:
Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Timer1_Timer()

    If GetAsyncKeyState(vbKeyF12) Then
        MsgBox "F12 was pressed!", vbInformation, "Info"
    End If

End Sub

Doesnt work i dun get a msg saying f12 was pressed
@ the guy above wiccan uhm where do you put in that code the button what u want to press

_________________
Back to top
View user's profile Send private message AIM Address
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Tue Oct 30, 2007 4:32 am    Post subject: Reply with quote

Use VK_F12 instead of vbKeyF12.
Back to top
View user's profile Send private message
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Tue Oct 30, 2007 4:37 am    Post subject: Reply with quote

rEakW0n wrote:
Use VK_F12 instead of vbKeyF12.

o right thanks for the quick reply il test it now Smile
Edit: Still no msg box
could you please give me a full code that works

_________________
Back to top
View user's profile Send private message AIM Address
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Tue Oct 30, 2007 4:50 am    Post subject: Reply with quote

Mussy69 wrote:
rEakW0n wrote:
Use VK_F12 instead of vbKeyF12.

o right thanks for the quick reply il test it now Smile
Edit: Still no msg box
could you please give me a full code that works


Well I don't know any VB.
But delphi, and in delphi it's VK_F12, but try this out:
Instead of VK_F12 or vbKeyF12, just use 123.

and if it still wont work, use this:
Code:
Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Timer1_Timer()

    If Odd(GetAsyncKeyState(VK_F12)) Then
        MsgBox "F12 was pressed!", vbInformation, "Info"
    End If

End Sub


and try it out with
VK_F12, vbKeyF12 and 123.
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: Tue Oct 30, 2007 6:34 am    Post subject: Reply with quote

Mussy69 wrote:
Doesnt work i dun get a msg saying f12 was pressed


You need to create a timer, and make sure it is enabled and has a valid interval to use my code.

rEakW0n wrote:
Use VK_F12 instead of vbKeyF12.


VB6 does not use 'VK_' keys unless you define them yourself. Instead, for GetAsyncKeyState, you simply use 'vbKey<keyhere>'.

And to use RegisterHotKey, you need to do something like this:

Code:
Option Explicit

'
' Structures
'
Private Type uMsg
    hWnd        As Long
    Message     As Long
    wParam      As Long
    lParam      As Long
End Type

'
' Constants
'
Private Const WM_HOTKEY = &H312
Private Const PM_REMOVE = &H1


'
' API Declarations
'
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal bytes As Long)
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As uMsg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long

'
' Used To Exit Loop
'
Private bExiting As Boolean

'
' Handle Hotkey Messages
'
Private Sub HandleHotkeys()
    Dim uMessage As uMsg
    Do While Not bExiting
        WaitMessage
        If PeekMessage(uMessage, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
            '
            ' Check For CTRL+F12
            '
            If LoWord(uMessage.lParam) = 2 And HiWord(uMessage.lParam) = vbKeyF12 Then
                MsgBox "Hotkey: CTRL+F12 was hit!"
            End If
        End If
        DoEvents
    Loop
End Sub

'
' Main Program Load
'
Private Sub Form_Load()
   
    '
    ' Show The Form
    ' This is important because DoEvents is used!
    '
    Me.Show
   
    ' Register F12
    Call RegisterHotKey(Me.hWnd, &H1FF&, 2, vbKeyF12)
    Call HandleHotkeys
End Sub

Private Sub Form_Unload(Cancel As Integer)
    bExiting = True
    Call UnregisterHotKey(Me.hWnd, &H1FF&)
End Sub


'
' HiWord
' Obtain the hiword of a param.
'
Function HiWord(ByVal value As Long) As Integer
    CopyMemory HiWord, ByVal VarPtr(value) + 2, 2
End Function

'
' LoWord
' Obtain the loword of a param.
'
Function LoWord(ByVal value As Long) As Integer
    CopyMemory LoWord, ByVal VarPtr(value), 2
End Function

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Oct 30, 2007 8:28 am    Post subject: Reply with quote

Mussy69 wrote:
rEakW0n wrote:
Use VK_F12 instead of vbKeyF12.

o right thanks for the quick reply il test it now Smile
Edit: Still no msg box
could you please give me a full code that works


Just, add a timer to your form. Double click on it and put in the code. By the way, I suggest RegisterHotKey because GetAsyncKeyState takes up more CPU Usage.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Oct 30, 2007 10:46 am    Post subject: Reply with quote

oib111 wrote:
Mussy69 wrote:
rEakW0n wrote:
Use VK_F12 instead of vbKeyF12.

o right thanks for the quick reply il test it now Smile
Edit: Still no msg box
could you please give me a full code that works


Just, add a timer to your form. Double click on it and put in the code. By the way, I suggest RegisterHotKey because GetAsyncKeyState takes up more CPU Usage.


No it really doesn't. Just compiled both codes I posted here to test your theory:

GetAsyncKeyState Project
- CPU Usage: 0%
- Memory Used: 4,892K

RegisterHotkey Project
- CPU Usage: 0%
- Memory Used: 5,020K

GetAsyncKeyState only takes up CPU based on the code of the project. If you code it correctly, it will run without issue at all. And will never take any CPU to monitor the key press.

RegHotKey is no different then GetAsyncKeyState. You have to monitor for the keypress in your message loop as well. In VB you use a timer because you do not have direct access to the message loop of your window without subclassing it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Trow
Grandmaster Cheater
Reputation: 2

Joined: 17 Aug 2006
Posts: 957

PostPosted: Tue Oct 30, 2007 4:21 pm    Post subject: Reply with quote

but if you use a vb timer (which is retarded; you might as well program your own control for a more accurate one) then of course the cpu usage will stay low... with a max of 1000 surveys per second. RegisterHotKey (which i dont know how to use) will at least give you a 100% likelihood of detecting a key press.

not much of an issue, but getasynckeystate in application failed me here and there cos of this.

_________________
Get kidnapped often.
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: Tue Oct 30, 2007 4:33 pm    Post subject: Reply with quote

blland wrote:
but if you use a vb timer (which is retarded; you might as well program your own control for a more accurate one) then of course the cpu usage will stay low... with a max of 1000 surveys per second. RegisterHotKey (which i dont know how to use) will at least give you a 100% likelihood of detecting a key press.

not much of an issue, but getasynckeystate in application failed me here and there cos of this.


Really? I haven't ever had an issue with GetAsyncKeyState to do the job. If needed you could always use threads instead of timers Wink

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Tue Oct 30, 2007 6:54 pm    Post subject: Reply with quote

oib111 wrote:
Mussy69 wrote:
rEakW0n wrote:
Use VK_F12 instead of vbKeyF12.

o right thanks for the quick reply il test it now Smile
Edit: Still no msg box
could you please give me a full code that works


Just, add a timer to your form. Double click on it and put in the code. By the way, I suggest RegisterHotKey because GetAsyncKeyState takes up more CPU Usage.

i had a timer but like wiccan said above u need a valid interval
my interval was jus default (0)
that registerhotkey code is massive
could you please go on MSN or PM me on what part of that script do i edit for instance if i wanted the hotkey "R" my MSN
is "[email protected]" and i dun care if the public no 1 cuz il jus delete them as a contact

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

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Oct 30, 2007 7:14 pm    Post subject: Reply with quote

With RegisterHotKey you need to understand that you HAVE to include a modifier. Which means your hotkey must use ALT+ CTRL+ SHIFT+ or WIN+ along side of another key. You can't just define your hotkey to a single button.

That being said..

ALT = &H1
CTRL = &H2
SHIFT = &H4
WIN = &H8

Next, you will need to pick which hotkey you want. Such as CTRL+R, ALT+R, etc. In this case, lets use CTRL+R.

In the Form_Load you will need to add the hotkey define:
Code:
Call RegisterHotKey(Me.hWnd, &H200&, 2, vbKeyR)


Also, before continuing be sure to add your remove hotkey call too, so add this in Form_Unload:
Code:
Call UnregisterHotKey(Me.hWnd, &H200&)


Notice that I used &H200& for this hotkey. It is the ID for the registered hotkey. And these MUST be different for each hotkey you define. Just increment by 1 for each one you want to have.

Next, you need to add the check inside the HandleHotkeys sub. So if you're looking at the old code, locate:

Code:
            '
            ' Check For CTRL+F12
            '
            If LoWord(uMessage.lParam) = 2 And HiWord(uMessage.lParam) = vbKeyF12 Then
                MsgBox "Hotkey: CTRL+F12 was hit!"
            End If


After, you will want to add the check for CTRL+R:
Code:
            '
            ' Check For R
            '
            If LoWord(uMessage.lParam) = 2 And HiWord(uMessage.lParam) = vbKeyR Then
                MsgBox "Hotkey: CTRL+R was hit!"
            End If


The HiWord of the lParam passed from the WM_HOTKEY message is the virtual key that was pressed. The loword is the modifier. (ALT, CTRL, SHIFT, WIN)

Hope that helps.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Tue Oct 30, 2007 8:18 pm    Post subject: Reply with quote

Wiccaan wrote:
With RegisterHotKey you need to understand that you HAVE to include a modifier. Which means your hotkey must use ALT+ CTRL+ SHIFT+ or WIN+ along side of another key. You can't just define your hotkey to a single button.

That being said..

ALT = &H1
CTRL = &H2
SHIFT = &H4
WIN = &H8

Next, you will need to pick which hotkey you want. Such as CTRL+R, ALT+R, etc. In this case, lets use CTRL+R.

In the Form_Load you will need to add the hotkey define:
Code:
Call RegisterHotKey(Me.hWnd, &H200&, 2, vbKeyR)


Also, before continuing be sure to add your remove hotkey call too, so add this in Form_Unload:
Code:
Call UnregisterHotKey(Me.hWnd, &H200&)


Notice that I used &H200& for this hotkey. It is the ID for the registered hotkey. And these MUST be different for each hotkey you define. Just increment by 1 for each one you want to have.

Next, you need to add the check inside the HandleHotkeys sub. So if you're looking at the old code, locate:

Code:
            '
            ' Check For CTRL+F12
            '
            If LoWord(uMessage.lParam) = 2 And HiWord(uMessage.lParam) = vbKeyF12 Then
                MsgBox "Hotkey: CTRL+F12 was hit!"
            End If


After, you will want to add the check for CTRL+R:
Code:
            '
            ' Check For R
            '
            If LoWord(uMessage.lParam) = 2 And HiWord(uMessage.lParam) = vbKeyR Then
                MsgBox "Hotkey: CTRL+R was hit!"
            End If


The HiWord of the lParam passed from the WM_HOTKEY message is the virtual key that was pressed. The loword is the modifier. (ALT, CTRL, SHIFT, WIN)

Hope that helps.

Ok so then for example
i would put the unload and load code
then i put the other code the 1 with "check for r" but say if i wanted to make an ac such as MzBot when u press F12 AC Starts
instead of MsgBox "Hotkey: CTRL+R was hit!" i would put...?
sorry for all the questions Confused Confused

_________________
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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