VirtualBox

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#6762 closed defect (invalid)

Cannot Move Cursor Using Windows API SetCursorPos Function -> working as designed

Reported by: Stewart Berman Owned by:
Component: guest additions Version: VirtualBox 3.2.0
Keywords: Cursor SetCursorPos Cc:
Guest type: Windows Host type: other

Description

VirtualBox 3.2.0 Add-ins 3.2.0

Host: Windows 7 Ultimate x64 Guest: Windows 7 Ultimate x64 Application: MS Access 2007

I am trying to move the mouse using VBA code in an Access 2007 form. I setup a test form with one button in the center of the form. In the click event of the botton I put:

Private Sub cmdMoveMouse_Click()

MoveMouseToTopLeftCorner Me.hwnd

End Sub

The listing for the module containing the MoveMouseToTopLeftCorner is at the end of this ticket.

If I open the database and press the button the cursor does not move although it does change from a hand (the hover cursor is set to hand) to an arrow which seems to indicate that the system thinks it has left the button. But it hasn't as I can click on the button again.

If I copy the database to a real Windows XP machine and do the same as above the cursor moves to the top left corner of the form and changes to an arrow (which is the expected resuls).

Module1:

Option Compare Database
Option Explicit

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type Point
x As Long
y As Long
End Type

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As Point) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long


Public Function MoveMouseToTopLeftCorner(ByVal vlHwnd As Long) As Boolean

Dim lReturn As Long

Dim pnt As Point

Dim rec As RECT

lReturn = GetWindowRect(vlHwnd, rec)
pnt.x = rec.Left
pnt.y = rec.Top
lReturn = SetCursorPos(pnt.x, pnt.y)

MoveMouseToTopLeftCorner = (0 <> lReturn)

End Function

Change History (3)

comment:1 by Stewart Berman, 14 years ago

I tried uninstalling the guest add-ins. Once I did that clicking on the button moved the cursor to the top left corner of the form. This is defintely an add-in issue.

comment:2 by Michael Thayer, 14 years ago

Resolution: invalid
Status: newclosed
Summary: Cannot Move Cursor Using Windows API SetCursorPos Function.Cannot Move Cursor Using Windows API SetCursorPos Function -> working as designed

Warping the mouse pointer is only really possible with a relative pointing device like a mouse. However the Additions provide an absolute pointing device on the lines of a touchscreen. If you think about it you can't really warp the pointer on a touchscreen either, as this would be akin to moving the user's finger programmatically. Obviously you can move the pointer temporarily (although the cursor sprite will not move as it is shared with the host), but as soon as the user moves the mouse on the host it will jump back to where it was.

In theory, we could of course allow the guest to control the host pointer, but for security reasons we do not want that.

comment:3 by Stewart Berman, 14 years ago

I understand the security concerns but it should be possible for the guest to move the mouse within the confines of the guest's screen. This does present a bit of a problem when using VB to development interactive training material.

However, for my testing purposes I can use Remote Desktop Connection which does allow the VM to control the mouse.

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use