|
-
Oct 13th, 2004, 11:38 AM
#1
Thread Starter
Addicted Member
Mousedown button (without clicking)
I have code that has been working using api to perform a clickbutton (sendmessage) (without actually using mouse to click), but now I switched the code to mousedown (because the button needs to repeat, and I have a timer enabled to repeat the command when mouse down, stop on mouseup). If I add a clickbutton event also, it messes with the mousedown and can send too many (an extra command) commands when the mouse button is released. Soo, how can I simulate a mousedown (and mouseup), so that I don't have to click. This is for a joystick to "click" a button. An alternative idea would be, how do I add a clickbutton event, but dont have it fire when the button is clicked, lol, just have it fire when SendMessage API says to Thanks!
-
Oct 13th, 2004, 11:45 AM
#2
Lively Member
Use the SetCursorPos API. Do a search, there should a few examples around on the forums.
You're writing a program to use a joystick like a mouse? I did one of those, if you wanted I could post it when I get a chance.
-
Oct 13th, 2004, 12:01 PM
#3
Thread Starter
Addicted Member
Is the setcursor api reliable? Like, will it reliably "find" the button regardless of the window position and button position, i.e. if they stretch, maximize, or move the window will it cause problems? I'll look into it either way though, thanks. I was hoping more for something that could just do the same as SendMessage, get the hwnd and send a mousedown and mouseup to it.
After looking into SetCursorPos a bit, I should also clarify that I would like it if this didn't have to move the mouse. Does setcursorapi actually move the mouse? It's name and what I read would suggest that it does. I would rather find a workaround and add clickbutton than have the mouse move also, but I wouldn't like this as it could cause problems with backedup commands later. Isn't there something I can do just to send "mousedown" and "mouseup" to a button if I know its hwnd?
Last edited by pjrage; Oct 13th, 2004 at 12:55 PM.
-
Apr 4th, 2005, 03:26 PM
#4
Junior Member
Re: Mousedown button (without clicking)
BootKing I could really use your code example when you get a chance.
Thanks
-
Apr 4th, 2005, 05:05 PM
#5
Re: Mousedown button (without clicking)
Ever thought about using DirectX's DirectInput to pull this off? With DirectInput, you have complete control over your input devices, and it reads/writes input directly from any input device rather than through windows messaging, which means it will not matter whether your form has focus or not. This can be any input device. Keyboard, Joystick, Mouse, Flight Stick, etc. Here is a mouse example:
http://externalweb.exhedra.com/Direc...N_Lesson02.asp
and I'm pretty sure in the DXCallback Sub, where you have control over the mouse, you should be able to make your mouse click without having to click it with no problem.
-
Apr 4th, 2005, 05:22 PM
#6
Re: Mousedown button (without clicking)
If I understand your question, you want to click a button from software, but disable the actual clicking that would occur if the user actually moved the mouse over there and clicked it manually.
Also I'm assuming that the program you are trying to click you do not have the source code for.
If these assumptions are true, then you may want to look into hooking the external application. (see example in my signature). If this looks like something you want to do we could discuss further.
-
Apr 4th, 2005, 07:51 PM
#7
Junior Member
Re: Mousedown button (without clicking)
Yes I have the Joystick class all ready to go from Direct X. However that is not the problem. The problem is how do I map the joystick controls to the mouse. Moving the mouse cursor is easy by using Me.Cursor.Position = New Point(x,y). The thing I can't figure out is how to execute mouse commands:
- mousedown
- click
- mouseup
I know there are events, and delegates all relevant to the mouse, but these are for taking action on the event after the fact.
I can do this in unmanaged code with a call to usr32.lib, but I do not want to do this.
One thing I also noticed about SetCursor it is not as smooth or as clean using the mouse. It begins to lagg if the application begins to become more complex. But if I switch back to the mouse everthing is normal. So is there another more direct way.
-
Apr 4th, 2005, 08:05 PM
#8
Re: Mousedown button (without clicking)
Since you mentioned that you know the hWnd of the control you want to click on you can simply send the WM_LBUTTONDOWN followed by the WM_LBUTTONUP messages.
VB Code:
Private Declare Function SendMessage _
Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Public Sub ClickWindow(ByVal hWnd As Long)
SendMessage hWnd, WM_LBUTTONDOWN, 0, ByVal 0
SendMessage hWnd, WM_LBUTTONUP, 0, ByVal 0
End Sub
-
Apr 4th, 2005, 08:07 PM
#9
Junior Member
Re: Mousedown button (without clicking)
I think your missing the point, I want a Managed code way of doing this. I know user32.lib can do what I want. But it is not good togo from Managed to Unmanged code.
-
Apr 4th, 2005, 08:10 PM
#10
Re: Mousedown button (without clicking)
 Originally Posted by VbNem
I think your missing the point, I want a Managed code way of doing this. I know user32.lib can do what I want. But it is not good togo from Managed to Unmanged code.
Oh... So you're using VB.Net? In that case you've posted your question in the wrong forum.
-
Apr 4th, 2005, 08:14 PM
#11
Junior Member
Re: Mousedown button (without clicking)
Ahh Oops.. Anyway of Dragging this a .Net forum?
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
|