Last active
May 12, 2025 05:30
-
-
Save ten9miq/7418b982a62e7511446f258769ceb976 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; RCtrl2連打でカーソルを現在のモニタの画面中央に移動 | |
; Alt+F1でモード切替 | |
; カーソルが存在するモニターの中央へ移動する | |
; 切替時のカーソルが存在するモニターの中央へ全モニターから移動する | |
#NoEnv | |
#Persistent | |
#InstallKeybdHook | |
SetBatchLines, -1 | |
; DPI 仮想化オフ & 物理ピクセル座標をそのまま使用 | |
DllCall("SetProcessDPIAware") | |
CoordMode, Mouse, Screen | |
; ダブルタップ閾値(ミリ秒) | |
doubleTapThreshold := 400 | |
;=== 設定ファイルのパス & 起動時に読み込み === | |
iniFile := A_ScriptDir "\RCtrl2連打でモニター中央に移動.ini" | |
IniRead, FixedMonitor, %iniFile%, Settings, FixedMonitor, 0 | |
FixedMonitor := FixedMonitor + 0 ; 数値化 | |
;=== Alt+F1 でモード切り替え === | |
!F1:: | |
; マウス位置取得 | |
MouseGetPos, mx, my | |
SysGet, totalMon, MonitorCount | |
; 現在いるモニター番号を判定 | |
currentMon := 0 | |
, % totalMon { | |
SysGet, mon, Monitor, %A_Index% | |
if (mx >= monLeft && mx <= monRight && my >= monTop && my <= monBottom) { | |
currentMon := A_Index | |
break | |
} | |
} | |
; モード切替:動的→固定、固定→動的 | |
if (FixedMonitor = 0) { | |
FixedMonitor := currentMon | |
} else { | |
FixedMonitor := 0 | |
} | |
; 設定ファイルに保存 | |
IniWrite, %FixedMonitor%, %iniFile%, Settings, FixedMonitor | |
; ツールチップ表示 | |
modeText := FixedMonitor | |
? "カーソル中央モニター " FixedMonitor " 固定" | |
: "動的移動" | |
ToolTip % "モード:" modeText | |
SetTimer, _RemoveTip, -1000 | |
return | |
;=== 右Ctrl ダブルタップでカーソル移動 === | |
~SC11D:: | |
if (A_PriorHotkey = A_ThisHotkey | |
&& A_TimeSincePriorHotkey < doubleTapThreshold) | |
{ | |
MouseGetPos, mx, my | |
SysGet, totalMon, MonitorCount | |
dest := FixedMonitor | |
if (dest = 0) { | |
; 動的モード:現在のモニターを再判定 | |
, % totalMon { | |
SysGet, mon, Monitor, %A_Index% | |
if (mx >= monLeft && mx <= monRight && my >= monTop && my <= monBottom) { | |
dest := A_Index | |
break | |
} | |
} | |
} | |
; 中央へ移動 | |
if (dest >= 1 && dest <= totalMon) { | |
SysGet, mon, Monitor, %dest% | |
cx := (monLeft + monRight)//2 | |
cy := (monTop + monBottom)//2 | |
MouseMove, %cx%, %cy%, 0 | |
} | |
} | |
return | |
;=== ツールチップを消すタイマー === | |
_RemoveTip: | |
ToolTip | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv | |
#Persistent | |
#InstallKeybdHook | |
SetBatchLines, -1 | |
; ① DPI 仮想化をオフにして物理ピクセル座標をそのまま使う | |
DllCall("SetProcessDPIAware") | |
; ② マウスはスクリーン(物理ピクセル)基準 | |
CoordMode, Mouse, Screen | |
; 2度押し判定の閾値 (ミリ秒) | |
doubleTapThreshold := 400 | |
; 右Ctrl (scancode 11D) を物理押下のみでフック | |
$SC11D:: | |
if (A_PriorHotkey = A_ThisHotkey | |
&& A_TimeSincePriorHotkey < doubleTapThreshold) | |
{ | |
; カーソル現在位置 | |
MouseGetPos, mx, my | |
; モニター数取得 | |
SysGet, totalMon, MonitorCount | |
, %totalMon% | |
{ | |
idx := A_Index | |
; ←ここで一度に左上/右下を取得 | |
SysGet, mon, Monitor, %idx% | |
l := monLeft | |
t := monTop | |
r := monRight | |
b := monBottom | |
if (mx >= l && mx <= r && my >= t && my <= b) | |
{ | |
cx := (l + r)//2 | |
cy := (t + b)//2 | |
; (デバッグ用)移動先を確認 | |
; ToolTip, % "Mon#: " idx "`n" | |
; . "Bounds: " l "," t " - " r "," b "`n" | |
; . "Center: " cx "," cy | |
; SetTimer, _RemoveTip, -600 | |
MouseMove, %cx%, %cy%, 0 | |
Break | |
} | |
} | |
} | |
Return | |
_RemoveTip: | |
ToolTip | |
Return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment