Forum Discussion

jenny's avatar
jenny
Occasional Contributor
14 years ago

How to get mouse state?

Hi,

I am using TC7.5 for automation test.

When run a script.function(the function content is empty), and at the same time do some manual operation on screen object, including click, dblclick, input, how to get mouse state, such as left click of mouse button, right click of mouse button, which api need I use?



Thanks

Jenny



  • Jenny,





    To get mouse position, you can use TestComplete's Sys.Desktop.MouseX and MouseY properties. 

    To get the state of mouse buttons, you have to use Windows API functions, for instance, GetKeyState:







    ' Use Win32API.VK_LBUTTON to get the state of the left mouse button

    ' Use Win32API.VK_RBUTTON to get the state of the right moust button

    ButtonState = Win32API.GetKeyState(Win32API.VK_LBUTTON)

    If (ButtonState and &H0080) <> 0 Then

      Log.Message "The left mouse button is pressed"

    Else

       Log.Message "The left mouse button is NOT pressed"

    End If




  • jenny's avatar
    jenny
    Occasional Contributor
    I tried with your method and got successful result for mouse button state.

    Thank you very much!



    B.R.

    Jenny