Mouse click!
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
How to make cursor click od certain position (just like with mouse)
outside your application...?
I guess this is solution:
http://www.devx.com/vb2themax/Tip/19299
but i really dont know how to use it.
thanks in advance...
outside your application...?
I guess this is solution:
http://www.devx.com/vb2themax/Tip/19299
but i really dont know how to use it.
thanks in advance...
<3 VB & Python
That uses the win32 function mouse_event, also it is in VB5/6 so the syntax might be a little different to VB.Net.
SendInput has superseded mouse_event so I'd recommend you use that instead.
The usage is in Button1_Click:
SendInput has superseded mouse_event so I'd recommend you use that instead.
The usage is in Button1_Click:
Code: Select all
Const MOUSEEVENTF_LEFTDOWN As UInteger = &H2
Const MOUSEEVENTF_LEFTUP As UInteger = &H4
Const MOUSEEVENTF_RIGHTDOWN As UInteger = &H8
Const MOUSEEVENTF_RIGHTUP As UInteger = &H10
Const MOUSEEVENTF_MIDDLEDOWN As UInteger = &H20
Const MOUSEEVENTF_MIDDLEUP As UInteger = &H40
Const MOUSEEVENTF_ABSOLUTE As UInteger = &H8000
Const MOUSEEVENTF_MOVE As UInteger = &H1
Public Structure MOUSEINPUT
Public dx As Integer
Public dy As Integer
Public mouseData As UInteger
Public dwFlags As UInteger
Public time As UInteger
Public dwExtraInfo As IntPtr
End Structure
Public Structure INPUT
Public type As UInteger
Public mi As MOUSEINPUT
End Structure
<DllImport("user32.dll")> Shared Function SendInput(ByVal nInputs As UInteger, ByRef pInputs As INPUT, ByVal cbSize As Integer) As UInteger
End Function
Dim inp As INPUT = New INPUT()
Dim inpsize As Integer = Marshal.SizeOf(inp)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'inp.mi.dwFlags = MOUSEEVENTF_MOVE 'move mouse relative to its current position
'inp.mi.dwFlags = MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE 'move to a set X/Y
'inp.mi.dx = 65535 / (Screen.PrimaryScreen.Bounds.Width / 50) 'this works with absolute positioning x:50, Y:100
'inp.mi.dy = 65535 / (Screen.PrimaryScreen.Bounds.Height / 100)
'inp.mi.dx = 30' this works with relative positioning +X:30, +Y:60
'inp.mi.dy = 60
'inp.mi.dwFlags = MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP 'simulate left click down/up
'inp.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP 'simulate right click down/up
'inp.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN Or MOUSEEVENTF_MIDDLEUP 'simulate middle click down/up
SendInput(1, inp, inpsize)
End Sub
Last edited by mandai on Thu Jan 26, 2012 11:51 pm, edited 2 times in total.
Sorry but i still cant get it to work...
could someone make source and post it here? (timer sets position and clicks on it)
thanks
could someone make source and post it here? (timer sets position and clicks on it)
thanks
<3 VB & Python
Clicks on what/where?
Code: Select all
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 3000 'delay
inp.mi.dwFlags = MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE
inp.mi.dx = 65535 / (Screen.PrimaryScreen.Bounds.Width / 5)
inp.mi.dy = 65535 / (Screen.PrimaryScreen.Bounds.Height / 10)
SendInput(1, inp, inpsize)
inp.mi.dwFlags = MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP
SendInput(1, inp, inpsize)
End Sub
Last edited by mandai on Thu Jan 26, 2012 11:54 pm, edited 2 times in total.
Yes
As the comments above say use MOUSEEVENTF_MOVE to move the cursor relative to its current position, and use (MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE) to move the cursor to an absolute position.
As the comments above say use MOUSEEVENTF_MOVE to move the cursor relative to its current position, and use (MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE) to move the cursor to an absolute position.
Thanks, that worked...
but if i set
any idea how to convert that inp.mi.dy into... well normal pixels
but if i set
Code: Select all
it comes almost in center of the screen and my monitor's resolution is 1280 X 1024inp.mi.dx = 25555
inp.mi.dy = 25555
any idea how to convert that inp.mi.dy into... well normal pixels
<3 VB & Python
SOLVED!
inp.mi.dx = (65535 / Screen.PrimaryScreen.Bounds.Width) * pixels
inp.mi.dy = (65535 / Screen.PrimaryScreen.Bounds.Height) * pixels
thanks for all help
inp.mi.dx = (65535 / Screen.PrimaryScreen.Bounds.Width) * pixels
inp.mi.dy = (65535 / Screen.PrimaryScreen.Bounds.Height) * pixels
thanks for all help
<3 VB & Python
Copyright Information
Copyright © Codenstuff.com 2020 - 2023