CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Mousekeys

  1. #1
    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    14

    Mousekeys

    Hi,

    I'm looking for a way to control the mouse from within a program, and I want to do this by using MouseKeys.
    In short I have a joystick hooked up to a microcontroller who sends directional data to the serialport and this data should be used to control the mousepointer. MouseKeys use the numerical keyboard to control the mouse and therefor I've tried to use keybd_event vbKeyNumpadX, 0, 0, 0
    keybd_event vbKeyNumpadX, 0, KEYEVENTF_KEYUP, 0

    I've also tried SendInput() and SendMessage() but I couldn't get it to work. I know that you can send keys with the SendKeys statement also, but I don't know how to send numerical keys with it. Does anyone know how to do this? Or any smart way to send numerical keys so that MouseKeys picks it up?
    (Btw, I tried to write my own "MouseKeys" using SetCursorPos(), but the result wasn't as smooth as the original.)

    I would really appreciate an answer.

    /Xplorer


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Mousekeys

    Here is something that shows how to control the mouse.
    Start a new project.
    Add a Textbox in the upper left corner then add a label next to it
    Add a second textbox below the first and add a label next to it
    Add a comandButton below the second textbox.Make it real wide for a long caption.
    Add a module to the project
    PAste this code into the Form and module.

    RUN it
    Enter values according to directions in the two textboxes and click the command button, Watch the mouse move.

    '
    '
    " This goes into the FORM
    option Explicit

    private Sub Command1_Click()
    MoveMouse Xpos.Text, Ypos.Text
    End Sub

    private Sub Form_Load()
    me.Top = 0
    me.Left = 0
    me.Width = Screen.Width
    me.Height = Screen.Height
    Label1.Caption = "X (Between 0 to " & Screen.Width / 15 & "):"
    Label2.Caption = "Y (Between 0 to " & Screen.Height / 15 & "):"
    End Sub
    Sub MoveMouse(x as Single, y as Single)
    Dim pt as POINTAPI
    pt.x = x
    pt.y = y
    ClientToScreen hwnd, pt
    SetCursorPos pt.x, pt.y
    End Sub
    '
    '
    ' THis goes into the module
    '
    option Explicit

    Type POINTAPI
    x as Long
    y as Long
    End Type

    Declare Function ClientToScreen Lib "user32" (byval hwnd as Long, lpPoint as POINTAPI) as Long
    Declare Function SetCursorPos Lib "user32" (byval x as Long, byval y as Long) as Long





    John G

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

Featured