Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21090

RegisterHotKey and ProcessMessages issue...

$
0
0
VB6
Windows 7, 64-Bit


I have a ListBox containing items like the following:

  • Press_A
  • Pause_1
  • Press_B

I am using a "switch" of sorts, changing the Form1.Tag to either be ON or OFF. This will tell me whether or not I can go ahead with my SendKeys or Pause code, depending on the text of the item the ListBox is currently on.

Therefore, my code begins the ProcessMessages loop, checks the switch, if it's ON then it performs my SendKeys or Pause code, and then goes on to see if the HotKey was pressed again. If it was not pressed, it loops back to see if the switch is still on. If it is, it performs the next item in the ListBox, and so on. Here is the code, followed by the problem I'm having:

Code:

Private Sub ProcessMessages()
Dim Message As Msg, myPress As String, myPause As String, HarsH

Do While Not bCancel
If Form1.Tag = "ON" Then
    If InStr(List1.List(i), "Press") Then
        myPress = GetToken(List1.List(i), "_", 2)
        CreateObject("WScript.Shell").SendKeys myPress, True
    End If
    If InStr(List1.List(i), "Pause") Then
        myPause = GetToken(List1.List(i), "_", 2)
        myPause = Val(myPause)
        Pause (myPause)
    End If
    i = i + 1
End If

If i = List1.ListCount - 1 Then
    'Turn it off
    Form1.Tag = "OFF"
    'Reset the i counter
    i = 0
End If

WaitMessage

If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
    If Form1.Tag = "OFF" Then
        Form1.Tag = "ON"
    Else
        Form1.Tag = "OFF"
    End If
End If

DoEvents
Loop
End Sub

It will fire the first and second items in the ListBox, but will not fire the third. I can pause the code, stepping through each line and they will all fire, but not when running the program without Breaks.

Any help would be appreciated as to why it is not processing all of the items in my ListBox.

Viewing all articles
Browse latest Browse all 21090

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>