简体   繁体   中英

Autohotkey Mousemove Wrong Monitor

I'm using mousegetpos to get the current mouse position. I click somewhere else. Then I try to restore the original postion with mousemove. The mouse moves to a different monitor. I tried the alternative method dllcall, with no success. How do I move the mouse back to the original monitor?

It's easier to help if you post your code - then people can see where you're going wrong.

This works fine for me when pressing the Ctrl - T hotkey:

CoordMode, Mouse, Screen

^t::
MouseGetPos, x, y
; Do Stuff Here.
MouseMove, x, y
return

The CoordMode, Mouse, Screen line sets the coordinates relative to the entire screen rather than the active window. I've tested this on my multiple monitor setup and the mouse goes back to the original location every time, even across monitors. Let me know if it's not working for you.

Also, just to make things a little smoother, you can set the mouse speed to '0' before moving the mouse with:

SetDefaultMouseSpeed, 0

This makes the mouse appear to move instantly which looks a little cleaner in most scripts.

I can confirm that Gary's answer works perfectly for anybody else out there having similar problems. Thanks, Gary!

I was myself having a problem like this with Breakaway Audio Enhancer...

For anybody that uses or knows Breakaway, you have to double-click on the toolbar (in the taskbar) to mute it. The way Breakaway works with the sound pipeline other standard AHK mute scripts won't work, so moving the mouse to the toolbar and double-clicking is really the only method of muting. I wanted Caps Lock to mute (or unmute) audio and preferably have the mouse return to where it originally was.

I've had countless problems trying to get this to work with multiple monitors until Gary's post, so here is my solution for anybody else having similar issues:

Capslock::
    BlockInput On
    CoordMode, Mouse, Screen
    MouseGetPos, xpos, ypos
    MouseClick, left, 42, 965, 2 ;change the co-ordinates to match your system
    MouseMove, xpos, ypos
    SetDefaultMouseSpeed, 0
    BlockInput Off
Return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM