Locking cursor movement

Hey guys

A while back, I came across a feature in MSDN that made it possible to lock the movement of a mouse within a specific area of the screen. I researched the Web but could not find it again (Maybe because it is very late or very early in the morning…). Any ideas on what it is called?

Thanks

Richard

See https://forum.xojo.com/12285-move-mouse-cursor-and-click-by-code-for-mac/0

The move cursor can be used to chill it in a specific place with a timer.

That said, it could be very disturbing for the customer, who may think the computer is stuck.

I think you want the ClipCursor function.

e.g. [code]

Declare Function ClipCursor Lib “User32” (RectArea As Ptr) As Boolean
Dim rect As New MemoryBlock(16)
rect.Int32Value(0) = 10 ’ X coord
rect.Int32Value(4) = 10 ’ Y coord
rect.Int32Value(8) = 100 ’ right coord
rect.Int32Value(12) = 100 ’ bottom coord
Call ClipCursor(rect)
[/code]

And to clear/reset:

  Declare Function ClipCursor Lib "User32" (RectArea As Ptr) As Boolean
  Call ClipCursor(Nil)

@Andrew: Exactly what I was looking for. Thanks a lot.

unfortunately, I cannot get it working…

I copied the first part in the Open event of the App and the second part in the Close event… Any ideas what I am doing wrong?

Richard

You have to use ClipCursor after the window has obtained input focus; Window.Open is too early. Try moving the code from Window.Open to the action event of a timer set to ModeSingle with a period of 1ms.

@Andrew: Success! Thanks a lot!

"Oh God, Oh God, I cant get my mouse out of this blasted window… what was the obscure set of keys had to press??’

Just alt+tab out of the window (or Ctrl+F4 to close it)

I was thinking of the way VMs grab the mouse. :slight_smile:

VMware ESX, ESXi, Workstation, Server, Player, Ace : Ctrl+Alt (Windows and Linux)
VMware Fusion: Ctrl-Cmd (Mac)
Microsoft Virtual Server 2005 R2, Hyper-V, Virtual PC 2007: Right Alt
Citrix XenServer: Ctrl+Alt
Virtual Iron: Ctrl+Alt
KVM, Qemu: Right Ctrl
Sun xVM xVM Server, VirtualBox: Right Ctrl
Parallels: Ctrl+Alt (Windows)
Parallels Workstation: Ctrl+Option(Alt) (Mac)

Don’t forget VirtualBox: Right Ctrl