Results 1 to 3 of 3

Thread: RegisterHotKey and ProcessMessages issue...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Question RegisterHotKey and ProcessMessages issue...

    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.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: RegisterHotKey and ProcessMessages issue...

    Well, I found that the program will continue.... only when I move my mouse. How does that even matter??? Super frustrated now.

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: RegisterHotKey and ProcessMessages issue...

    Quote Originally Posted by Conroy Vanderbluff View Post
    Well, I found that the program will continue.... only when I move my mouse. How does that even matter???
    That's the pitfall of using the WaitMessage function.

    Quote Originally Posted by MSDN
    The WaitMessage function suspends the thread and does not return until a new message is placed in the thread's message queue.
    I've used a subroutine very similar to your ProcessMessages() procedure some time ago and I've realized that it's a very hackish way of receiving the WM_HOTKEY message. The proper way of handling that message is by subclassing. The attached project here demonstrates how.


    BTW, can you tell us what your app is trying to do? It looks like you are automating something. Am I right?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width