|
-
Jul 2nd, 2010, 02:02 PM
#41
Thread Starter
Fanatic Member
Re: Global Mouse Hook
 Originally Posted by yo mismo
¿Your textboxes are named "X1", "Y1" literal?
Yes they are up to 15
-
Jul 2nd, 2010, 02:04 PM
#42
Frenzied Member
Re: Global Mouse Hook
yes:
vb Code:
If cAmount = 1 Then
i = 1
Me.Invoke(updatebox,new object(){"X" & i.ToString, "Y" & i.ToString, p.X.ToString, p.Y.ToString})
'UpdateTB("X" & i.ToString, "Y" & i.ToString, p.X, p.Y)
Threading.Thread.Sleep(500)
cAmount = 2
'and so on
-
Jul 2nd, 2010, 02:29 PM
#43
Thread Starter
Fanatic Member
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
-
Jul 2nd, 2010, 02:46 PM
#44
Frenzied Member
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)
-
Jul 2nd, 2010, 02:51 PM
#45
Thread Starter
Fanatic Member
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
-
Jul 2nd, 2010, 03:21 PM
#46
Frenzied Member
Re: Global Mouse Hook
Here is the code:
vb Code:
Public Class Form1
Public Delegate Sub Hello(ByVal a As String)
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort
Private running As Boolean = True
Private t As System.Threading.Thread
Private t2 As System.Threading.Thread
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
t = New Threading.Thread(New Threading.ThreadStart(AddressOf threadfunc))
t2 = New Threading.Thread(New Threading.ThreadStart(AddressOf threadfunc2))
t.Start()
t2.Start()
End Sub
Public Sub threadfunc()
While running
Dim lbpushed As Boolean = KeyStatus(Keys.LButton)
If lbpushed Then
Dim d As New Hello(AddressOf Me.updateTB)
Me.Invoke(d, New Object() {MousePosition.ToString})
End If
End While
End Sub
Public Sub threadfunc2()
While running
Threading.Thread.Sleep(20)
Dim d As New Hello(AddressOf Me.updateLbl)
Me.Invoke(d, New Object() {MousePosition.ToString})
End While
End Sub
Public Sub updateTB(ByVal value As String)
Me.TextBox1.Text = value
'This was for testing the setting of a text box if you were using an increment as an identifier.
'Dim one as Integer = 1
'Dim text1 as TextBox = CType(Me.Controls("TextBox" + one.ToString),TextBox)
'text1.Text = value
End Sub
Public Sub updateLbl(ByVal value As String)
Me.LinkLabel1.Text = value
End Sub
Public Shared ReadOnly Property KeyStatus(ByVal Key As Keys) As Boolean
Get
If Key = Keys.LButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
Key = Keys.LButton
MessageBox.Show("left button pushed")
ElseIf Key = Keys.RButton AndAlso Not My.Computer.Mouse.ButtonsSwapped Then
Key = Keys.RButton
MessageBox.Show("right button pushed")
End If
Return GetAsyncKeyState(Key) And &H8000US
End Get
End Property
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Try
t.Abort()
t2.Abort()
Catch ex As Exception
If t.IsAlive Then
t.Abort()
End If
If t2.IsAlive Then
t.Abort()
End If
End Try
t.Join()
t2.Join()
End Sub
End Class
Just add a LinkLabel and a TextBox to your form for testing this code...
Justin
-
Jul 2nd, 2010, 03:48 PM
#47
Thread Starter
Fanatic Member
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??
-
Jul 2nd, 2010, 04:22 PM
#48
Thread Starter
Fanatic Member
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??
-
Jul 2nd, 2010, 06:23 PM
#49
Thread Starter
Fanatic Member
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
-
Jul 6th, 2010, 08:39 AM
#50
Frenzied Member
Re: Global Mouse Hook
Did you get it working finally?
Justin
-
Jul 6th, 2010, 10:01 AM
#51
Thread Starter
Fanatic Member
Re: Global Mouse Hook
Yes thankyou for the help the program i made is in my signiture if u want to try it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|