Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,456 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,925 people online right now. Registration is fast and FREE... Join Now!




Visual Basic 6.0 HotKey

 
Reply to this topicStart new topic

Visual Basic 6.0 HotKey, Help with HotKey

koolazngy94
30 Jul, 2008 - 09:51 AM
Post #1

New D.I.C Head
*

Joined: 29 Jul, 2008
Posts: 22

I need help with this HotKey. I want to press F2 outside the program to start auto clicker but it won't start. Is there a way to do that?

CODE
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vKeyF1 Then
    Timer1.Enabled = False
    Command1.Caption = "Start"
    Text1.Enabled = True
    Else
        If KeyCode = vbKeyF2 Then
            Timer1.Enabled = True
            Command1.Caption = "Stop"
            Text1.Enabled = False
        End If
        End If
End Sub

User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Visual Basic 6.0 HotKey
30 Jul, 2008 - 12:30 PM
Post #2

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
You could go the route of a global hotkey, though I find that API troublesome and I've had a hard time finding good info on it in the past. I think an easier way is to set a timer with a fast interval and check if it's pressed down with the GetAsyncKeyState API.

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


CODE
Public Function HotKey(ByVal KeyCode As Integer) As Boolean

    'Call it once to clear its old data
    GetAsyncKeyState 113

    'Now actually check for the key
    If GetAsyncKeyState(113) Then
        HotKey = True
    Else
        HotKey = False
    End If

End Function


This post has been edited by Zhalix: 30 Jul, 2008 - 12:33 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:31PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month