Results 1 to 11 of 11

Thread: Mousedown button (without clicking)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    185

    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!

  2. #2
    Lively Member Bootking's Avatar
    Join Date
    Mar 2003
    Location
    Marquette University
    Posts
    90
    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.
    Check out my band's website!
    Walter Walker Band

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    185
    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.

  4. #4
    Junior Member
    Join Date
    Jul 2004
    Posts
    25

    Re: Mousedown button (without clicking)

    BootKing I could really use your code example when you get a chance.

    Thanks

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    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.

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  7. #7
    Junior Member
    Join Date
    Jul 2004
    Posts
    25

    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.


  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Private Declare Function SendMessage _
    2.  Lib "user32.dll" Alias "SendMessageA" ( _
    3.  ByVal hwnd As Long, _
    4.  ByVal wMsg As Long, _
    5.  ByVal wParam As Long, _
    6.  ByRef lParam As Any) As Long
    7.  
    8. Private Const WM_LBUTTONDOWN As Long = &H201
    9. Private Const WM_LBUTTONUP As Long = &H202
    10.  
    11. Public Sub ClickWindow(ByVal hWnd As Long)
    12.     SendMessage hWnd, WM_LBUTTONDOWN, 0, ByVal 0
    13.     SendMessage hWnd, WM_LBUTTONUP, 0, ByVal 0
    14. End Sub

  9. #9
    Junior Member
    Join Date
    Jul 2004
    Posts
    25

    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.

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Mousedown button (without clicking)

    Quote 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.

  11. #11
    Junior Member
    Join Date
    Jul 2004
    Posts
    25

    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
  •  



Click Here to Expand Forum to Full Width