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 


[VB6]Enabling Timer with hotkey help
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
Dillonz
Grandmaster Cheater
Reputation: 4

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

PostPosted: Sat Jun 07, 2008 9:38 am    Post subject: [VB6]Enabling Timer with hotkey help Reply with quote

How can I do it? The auto clicker can click up to very fast speeds but it can also be hard to stop(almost impossible). I want the hotkey to be "Ctrl+1".
Thanks.
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

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

PostPosted: Sat Jun 07, 2008 9:52 am    Post subject: Reply with quote

Did you even try to figure out how to do this. Because nobody here is going to just give you code. This section is for helping, not giving. Try to code it, if you have problems then come back here. But as for registering the hotkey, I would use the RegisterHotKey API.
_________________


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
Dillonz
Grandmaster Cheater
Reputation: 4

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

PostPosted: Sat Jun 07, 2008 10:18 am    Post subject: Reply with quote

I tried figuring out by editing some code I found but all attempts failed Crying or Very sad
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

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

PostPosted: Sat Jun 07, 2008 10:35 am    Post subject: Reply with quote

Well post what you have. Here's what I would do if it were C++. Not quite sure how to make this to vb though.

Code:

#define IDC_AC_HOTKEY 100
bool bHotkey = FALSE;
RegisterHotKey(hwnd, IDC_AC_HOTKEY, MOD_CONTROL, VK_KEY_1);

//other coding

case WM_HOTKEY:
   if(bHotkey) {
      bHotkey = FALSE;
   }
   else {
      bHotkey = TRUE;
   }
   break;
case WM_TIMER:
   while(bHotkey) {
      //ac code
   }
   break;
//more cases and coding
UnregisterHotKey(hwnd, IDC_AC_HOTKEY);

[/code]

_________________


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
Dillonz
Grandmaster Cheater
Reputation: 4

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

PostPosted: Sat Jun 07, 2008 11:00 am    Post subject: Reply with quote

Ummm... If you're not sure about VB why would you post C++?
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

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

PostPosted: Sat Jun 07, 2008 11:34 am    Post subject: Reply with quote

I could have posted nothing, and you wouldn't have had any idea on how to use APIs. At least you know how to use them now.
_________________


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: 8588
Location: 127.0.0.1

PostPosted: Sat Jun 07, 2008 12:24 pm    Post subject: Reply with quote

obi: You need to chill with your new found attitude. If you are going to get snippy with people don't bother posting.

Dillio: You can either register the hotkey using RegisterHotkey, but this would cause you to need to subclass in VB. Instead, I would suggest just using GetAsyncKeyState. You can capture a keypress via a timer then.

For example heres some code to activate a timer if the user presses F12:

Code:
Option Explicit

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

Private Sub Form_Load()

    '// Timer1 is our hotkey monitor timer.
    Timer1.Enabled = True
    Timer1.Interval = 10
   
    '// Timer2 is our function timer which is enabled when
    '// our hotkey is pressed.
    Timer2.Enabled = False
    Timer2.Interval = 1

End Sub

Private Sub Timer1_Timer()
    If (GetAsyncKeyState(vbKeyF12) And 1) Then
        Timer2.Enabled = True
    End If
End Sub

Private Sub Timer2_Timer()
    MsgBox "Our hotkey was pressed.."
    Timer2.Enabled = False
End Sub


Just add two timers with default properties to your project, the Form_Load even will set the needed properties for the timers. Then test it by running it and pressing F12 while it's running.

_________________
- 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: Sat Jun 07, 2008 12:31 pm    Post subject: Reply with quote

Sorry. I have a question, is there a way to define a program local hotkey instead of using registerhotkey which makes a system wide hotkey. And get you use GetAsyncKeyState to catch more than one key? For example, something like...

Code:

if(GetAsyncKeyState(VK_CONTROL && 0x5A)) {
   //do whatever
}

_________________


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: 8588
Location: 127.0.0.1

PostPosted: Sat Jun 07, 2008 12:37 pm    Post subject: Reply with quote

Code:
Private Sub Timer1_Timer()
    If ((GetAsyncKeyState(vbKeyControl)) And GetAsyncKeyState(vbKeyF12)) Then
        Timer2.Enabled = True
    End If
End Sub

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

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

PostPosted: Sat Jun 07, 2008 12:39 pm    Post subject: Reply with quote

Thanks Wiccan you rock!
Edit: Btw how could you make a combination of keys to activate? Just add a + ?


Last edited by Dillonz on Sat Jun 07, 2008 12:43 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sat Jun 07, 2008 12:40 pm    Post subject: Reply with quote

But you shouldn't use GetAsyncKeyState, since you have to call it constantly, I prefer RegisterHotKey, if you use VB.NET you can redirect the message hook to your own function and then on WM_HOTKEY message call your function.
Back to top
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sat Jun 07, 2008 12:41 pm    Post subject: Reply with quote

Make sure you put this in a module first!

Code:
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Sat Jun 07, 2008 12:45 pm    Post subject: Reply with quote

Symbol wrote:
But you shouldn't use GetAsyncKeyState, since you have to call it constantly, I prefer RegisterHotKey, if you use VB.NET you can redirect the message hook to your own function and then on WM_HOTKEY message call your function.


As I said above, with RegisterHotKey in VB6, you have to subclass the WndProc since you do not have direct access to it. If he didn't know how to use a hotkey, I highly doubt he knows how to subclass which I didn't want to post an example of as it's more work the needed.

HornyAZNBoy wrote:
Make sure you put this in a module first!


You do not need to put API declarations inside modules. You only need to place them in a module if you plan to use them throughout the code and not in a single file. As my example shows, the declare must be private in a Form object, but, you can use them perfectly fine inside a Form.

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

Joined: 23 May 2007
Posts: 181
Location: Where you least expect me.

PostPosted: Sat Jun 07, 2008 2:53 pm    Post subject: Reply with quote

Quick question. . . what are the pros/cons of using GetAsyncKeyState vs. RegisterHotKey? I have never used RegisterHotKey before I'm guessing it is global also. If so what is the diffrence?
_________________

.erutangis ruoy ni siht esu neht ,sdrawkcab siht daer ot hguone trams erew uoy fI
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

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

PostPosted: Sun Jun 08, 2008 2:13 am    Post subject: Reply with quote

Quote:
Quick question. . . what are the pros/cons of using GetAsyncKeyState vs. RegisterHotKey? I have never used RegisterHotKey before I'm guessing it is global also. If so what is the diffrence?


GetAsyncKeyState simply returns the value of the current key being pressed, so it needs to be looped very often to make sure it doesn't miss the press, it doesn't take too much memory

RegisterHotKey is a global hotkey that you have to declare, upside is that you dont need a loop for it. Downside is that if you want to use a large amount of keys (ie, your whole keyboard) you need to declare, create and destroy all of them in your code, which can be quite long

RegisterHotKey is generally a better idea, especially for the kind of thing dillio wants to do

_________________
Back to top
View user's profile Send private message
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