Page 2 of 2 FirstFirst 12
Results 41 to 51 of 51

Thread: [RESOLVED] Global Mouse Hook

  1. #41

  2. #42
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Global Mouse Hook

    yes:

    vb Code:
    1. If cAmount = 1 Then
    2.                         i = 1
    3.                         Me.Invoke(updatebox,new object(){"X" & i.ToString, "Y" & i.ToString, p.X.ToString, p.Y.ToString})
    4.                         'UpdateTB("X" & i.ToString, "Y" & i.ToString, p.X, p.Y)
    5.                         Threading.Thread.Sleep(500)
    6.                         cAmount = 2
    7. 'and so on
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #43

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Global Mouse Hook

    Ok changed all that now i get this error where i got an error before, ok this is my code so far. The error is near the bottom. the error is: Object reference not set to an instance of an object.
    Code:
        Private Sub threadfunc()
            Dim obj As Object = Me.Invoke(d)
            Dim p As Point = CType(obj, Point)
            While running
                Dim Rclick As Boolean = KeyStatus(Keys.RButton)
                Dim Lclick As Boolean = KeyStatus(Keys.LButton)
                If CollectingStarted = True Then
                    If Lclick Then
                        If cAmount = 1 Then
                            i = 1
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 2
                        ElseIf cAmount = 2 Then
                            i = 2
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 3
                        ElseIf cAmount = 3 Then
                            i = 3
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 4
                        ElseIf cAmount = 4 Then
                            i = 4
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 5
                        ElseIf cAmount = 5 Then
                            i = 5
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 6
                        ElseIf cAmount = 6 Then
                            i = 6
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 7
                        ElseIf cAmount = 7 Then
                            i = 7
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 8
                        ElseIf cAmount = 8 Then
                            i = 8
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 9
                        ElseIf cAmount = 9 Then
                            i = 9
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 10
                        ElseIf cAmount = 10 Then
                            i = 10
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 11
                        ElseIf cAmount = 11 Then
                            i = 11
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 12
                        ElseIf cAmount = 12 Then
                            i = 12
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 13
                        ElseIf cAmount = 13 Then
                            i = 13
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 14
                        ElseIf cAmount = 14 Then
                            i = 14
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 15
                        ElseIf cAmount = 15 Then
                            i = 15
                            Me.Invoke(updatebox, New Object() {"X" & i.ToString, "Y" & i.ToString, MousePosition.X.ToString, MousePosition.Y.ToString})
                            Threading.Thread.Sleep(500)
                            cAmount = 16
                        End If
                    End If
                    If Rclick Then
    
                    End If
                End If
            End While
    
        Public Sub UpdateTB(ByVal TB1 As String, ByVal TB2 As String, ByVal x As String, ByVal y As String)
            Dim txtbox1 As TextBox = CType(Me.Controls(TB1), TextBox)
    
            Dim txtbox2 As TextBox = CType(Me.Controls(TB2), TextBox)
    
            txtbox1.Text = x   <--- ERROR: Object reference not set to an instance of an object.
    
            txtbox2.Text = y   <--- ERROR: Object reference not set to an instance of an object.
        End Sub

  4. #44
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Global Mouse Hook

    Are you sure you have the textbox's named:

    X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,
    Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8,Y9,Y10,Y11,Y12,Y13,Y14 and Y15 ?

    Because if I pass the correct name of the textbox to that UpdateTB function, my textbox gets updated correctly with no error.

    Justin

    P.S

    does that error occur when you call the delegate in the very first if? Or does it happen in a follow if (..cAmount = 2, ...cAmout = 3)
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  5. #45

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Global Mouse Hook

    Yes they are definatly called X1 and Y1 up to 15 because i hand named them and it happens as soon as i click once, so yes on the first IF
    P.S can you post your code, i will see if anything is different to mine. Thankyou

  6. #46
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Global Mouse Hook

    Here is the code:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Public Delegate Sub Hello(ByVal a As String)
    4.  
    5.     Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort
    6.  
    7.     Private running As Boolean = True
    8.     Private t As System.Threading.Thread
    9.     Private t2 As System.Threading.Thread
    10.  
    11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    12.         t = New Threading.Thread(New Threading.ThreadStart(AddressOf threadfunc))
    13.         t2 = New Threading.Thread(New Threading.ThreadStart(AddressOf threadfunc2))
    14.         t.Start()
    15.         t2.Start()
    16.  
    17.     End Sub
    18.  
    19.      Public Sub threadfunc()
    20.         While running
    21.  
    22.             Dim lbpushed As Boolean = KeyStatus(Keys.LButton)
    23.  
    24.             If lbpushed Then
    25.                 Dim d As New Hello(AddressOf Me.updateTB)
    26.                 Me.Invoke(d, New Object() {MousePosition.ToString})
    27.             End If
    28.  
    29.  
    30.         End While
    31.     End Sub
    32.  
    33.     Public Sub threadfunc2()
    34.  
    35.         While running
    36.  
    37.             Threading.Thread.Sleep(20)
    38.             Dim d As New Hello(AddressOf Me.updateLbl)
    39.             Me.Invoke(d, New Object() {MousePosition.ToString})
    40.  
    41.         End While
    42.  
    43.     End Sub
    44.  
    45.     Public Sub updateTB(ByVal value As String)
    46.  
    47.         Me.TextBox1.Text = value
    48.  
    49.         'This was for testing the setting of a text box if you were using an increment as an identifier.
    50.         'Dim one as Integer = 1
    51.         'Dim text1 as TextBox = CType(Me.Controls("TextBox" + one.ToString),TextBox)
    52.         'text1.Text = value
    53.  
    54.     End Sub
    55.  
    56.     Public Sub updateLbl(ByVal value As String)
    57.  
    58.         Me.LinkLabel1.Text = value
    59.  
    60.     End Sub
    61.  
    62.     Public Shared ReadOnly Property KeyStatus(ByVal Key As Keys) As Boolean
    63.         Get
    64.             If Key = Keys.LButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
    65.                 Key = Keys.LButton
    66.                 MessageBox.Show("left button pushed")
    67.             ElseIf Key = Keys.RButton AndAlso Not My.Computer.Mouse.ButtonsSwapped Then
    68.                 Key = Keys.RButton
    69.                 MessageBox.Show("right button pushed")
    70.             End If
    71.             Return GetAsyncKeyState(Key) And &H8000US
    72.         End Get
    73.     End Property
    74.  
    75.     Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    76.         Try
    77.             t.Abort()
    78.             t2.Abort()
    79.         Catch ex As Exception
    80.             If t.IsAlive Then
    81.                 t.Abort()
    82.             End If
    83.             If t2.IsAlive Then
    84.                 t.Abort()
    85.             End If
    86.         End Try
    87.         t.Join()
    88.         t2.Join()
    89.     End Sub
    90.  
    91.  
    92. End Class

    Just add a LinkLabel and a TextBox to your form for testing this code...

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  7. #47

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Global Mouse Hook

    Right i tried to apply the parts of this to mine but this is really different and it would mean changin everything, Can i just ask what does "Object reference not set to instance of a object" mean??

  8. #48

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Global Mouse Hook

    In yours you dont put the X in one txtbox and the Y in another you just put the whole string in one textbox, can u try it when putting each value in different textboxes please. Im really stuck here. The error i get means that txtbox1 = Nothing and txtbox2 = Nothing how can i make them not equal Nothing??

  9. #49

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Global Mouse Hook

    ok i had to do it separate because i couldn't find out why it was throwing that exception.
    like this
    Code:
        Public Sub UpdateTB1(ByVal x As String, ByVal y As String)
            If cAmount = 1 Then
                Dim text1 As TextBox = X1
                Dim text2 As TextBox = Y1
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 2 Then
                Dim text1 As TextBox = X2
                Dim text2 As TextBox = Y2
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 3 Then
                Dim text1 As TextBox = X3
                Dim text2 As TextBox = Y3
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 4 Then
                Dim text1 As TextBox = X4
                Dim text2 As TextBox = Y4
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 5 Then
                Dim text1 As TextBox = X5
                Dim text2 As TextBox = Y5
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 6 Then
                Dim text1 As TextBox = X6
                Dim text2 As TextBox = Y6
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 7 Then
                Dim text1 As TextBox = X7
                Dim text2 As TextBox = Y7
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 8 Then
                Dim text1 As TextBox = X8
                Dim text2 As TextBox = Y8
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 9 Then
                Dim text1 As TextBox = X9
                Dim text2 As TextBox = Y9
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 10 Then
                Dim text1 As TextBox = X10
                Dim text2 As TextBox = Y10
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 11 Then
                Dim text1 As TextBox = X11
                Dim text2 As TextBox = Y11
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 12 Then
                Dim text1 As TextBox = X12
                Dim text2 As TextBox = Y12
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 13 Then
                Dim text1 As TextBox = X13
                Dim text2 As TextBox = Y13
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 14 Then
                Dim text1 As TextBox = X14
                Dim text2 As TextBox = Y14
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 15 Then
                Dim text1 As TextBox = X15
                Dim text2 As TextBox = Y15
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 16 Then
                Dim text1 As TextBox = X16
                Dim text2 As TextBox = Y16
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 17 Then
                Dim text1 As TextBox = X17
                Dim text2 As TextBox = Y17
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 18 Then
                Dim text1 As TextBox = X18
                Dim text2 As TextBox = Y18
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 19 Then
                Dim text1 As TextBox = X19
                Dim text2 As TextBox = Y19
                text1.Text = x
                text2.Text = y
            ElseIf cAmount = 20 Then
                Dim text1 As TextBox = X20
                Dim text2 As TextBox = Y20
                text1.Text = x
                text2.Text = y
                MsgBox("Maximum coorinate capacity reached!", MsgBoxStyle.Exclamation, "Max Capacity")
            End If
        End Sub

  10. #50
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Global Mouse Hook

    Did you get it working finally?

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  11. #51

Page 2 of 2 FirstFirst 12

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