我有一台笔记本电脑,它有主屏幕(A)和连接屏幕(B)。
有时鼠标在一个屏幕(B)上,而我想让它在另一个屏幕(A)上,但我只是看着没有鼠标的屏幕(A)。我可以拖动很多并寻找它,看它是否出现在 A 上,或者如果 B 处于打开状态,我可以把头转向 B 以查看光标在它上面的位置(B)..这样我就可以知道它何时会到达 A,但如果我可以使用键盘快捷键将鼠标光标放在笔记本电脑屏幕(A)的中间,那就更容易了。
因此,只需按一个键即可将光标从一个屏幕移动到另一个屏幕,然后移动到我知道的位置,例如中心。即使是鼠标移动也可以,只要移动或按键在鼠标所在的位置有效,就可以了。有办法吗?
答案1
答案2
该脚本对我有用:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force ; if the script is updated, replace the one and only instance
!m::
; 80 = CM_MONITORS - which basically means - monitor count
SysGet, count, 80
if count !=2 return ; only handle duo, uno - nothing to do
CoordMode, Mouse, Screen ; this is a must as the mouse coordinate are now relative to the whole screen (both monitors)
SysGet, mon_1, Monitor, 1
SysGet, mon_2, Monitor, 2
MouseGetPos mouse_x,mouse_y
; toggle the mouse to the middle of the other screen
if (mouse_x <= mon_1Right)
{
new_x := mon_2Left + (mon_2Right - mon_2Left) // 2
new_y := mon_2Top + (mon_2Bottom - mon_2Top) // 2
}
else
{
new_x := mon_1Left + (mon_1Right - mon_1Left) // 2
new_y := mon_1Top + (mon_1Bottom - mon_1Top) // 2
}
MouseMove, %new_x%, %new_y%
Click
return
Esc::ExitApp ; Exit script with Escape key
答案3
写了我自己的剧本v2因为先前答案中的脚本在 v1 中。
- 可与任意数量的显示器配合使用。
- 处理不同显示器上的不同 DPI 分辨率。
- 前进/后退鼠标按钮切换到下一个/上一个监视器。
- 将光标移动到显示器上相同的(缩放)相对位置切换到
#SingleInstance Force
MouseSwitchMonitor(switchNumber := 1) {
DllCall("SetThreadDpiAwarenessContext", "ptr", -3, "ptr") ; handles multiple monitors with different DPI settings
CoordMode("Mouse", "Screen")
count := MonitorGetCount()
if (count <= 1) {
return
}
MouseGetPos(&mouseX, &mouseY)
relativeMouseX := 0.5
relativeMouseY := 0.5
mouseMonitor := 0
monitors := {}
counter := 1
Loop count {
actual := MonitorGet(counter, &left, &top, &right, &bottom)
monitors.%actual% := {left: left, top: top, right: right, bottom: bottom}
if (left <= mouseX && mouseX < right && top <= mouseY && mouseY < bottom) { ; from testing, seems mouse position can be left or top but not right or bottom
mouseMonitor := actual
relativeMouseX := (mouseX - left) / (right - left)
relativeMouseY := (mouseY - top) / (bottom - top)
}
counter++
}
mouseMonitor := Mod(mouseMonitor - 1 + Mod(switchNumber, count) + count, count) + 1 ; modular arithmetic to cycle, and make sure 1 <= mouseMonitor <= count
if (!HasProp(monitors, mouseMonitor)) {
return
}
monitor := monitors.%mouseMonitor%
MouseMove(monitor.left + Floor(relativeMouseX * (monitor.right - monitor.left)), monitor.top + Floor(relativeMouseY * (monitor.bottom - monitor.top)), 0) ; since mouse position can be left or top, but not right or bottom
}
XButton1::MouseSwitchMonitor(-1) ; backward mouse button, previous monitor
XButton2::MouseSwitchMonitor(1) ; forward mouse button, next monitor