自宅時間が増え、自宅パソコンをいじる機会が多くなったので、これを機にパソコンの作業環境を整える。
まずは、ウィンドウ操作関連のショートカットの整備する。以前にAutohotkeyのスクリプトを作成してから、かなりの期間がたっており、状況も変わっていると思うので、スクリプトを作りなおしてみた。
スクリプトの内容は以下。
;===================================================================
; アクティブウィンドウのあるモニタを情報を返却する。
;===================================================================
GetCurrentMonitor(x,y,w,h){
SysGet, MonitorCount, MonitorCount
Loop, %MonitorCount%
{
SysGet, MonitorWorkArea, MonitorWorkArea, %A_Index%
if(x+w/2 >= MonitorWorkAreaLeft AND x+w/2 <= MonitorWorkAreaRight){
if(y >= MonitorWorkAreaTop AND y <= MonitorWorkAreaBottom){
;モニタの左上とセンタの座標を求める
if(MonitorWorkAreaLeft<MonitorWorkAreaRight){
MonitorW:=MonitorWorkAreaRight-MonitorWorkAreaLeft
CenterX:=MonitorWorkAreaLeft+(MonitorWorkAreaRight-MonitorWorkAreaLeft)/2
}
else{
MonitorW:=Abs(MonitorWorkAreaLeft)-Abs(MonitorWorkAreaRight)
CenterX:=MonitorWorkAreaLeft+(Abs(MonitorWorkAreaLeft)-Abs(MonitorWorkAreaRight))/2
}
if(MonitorWorkAreaTop<MonitorWorkAreaBottom){
MonitorH:=MonitorWorkAreaBottom-MonitorWorkAreaTop
CenterY:=MonitorWorkAreaTop+(MonitorWorkAreaBottom-MonitorWorkAreaTop)/2
}
else{
MonitorH:=Abs(MonitorWorkAreaTop)-Abs(MonitorWorkAreaBottom)
CenterY:=MonitorWorkAreaTop+(Abs(MonitorWorkAreaTop)-Abs(MonitorWorkAreaBottom))/2
}
Return % MonitorWorkAreaLeft . " " . MonitorWorkAreaTop . " " . MonitorW . " " . MonitorH . " " . CenterX . " " . CenterY
}
}
Exit
}
}
;===================================================================
; fvwm風ウィンドウ制御(マルチモニタ対応)
;===================================================================
^+!i::
WinGet,id,ID,A
if(x%id%=""){
WinGetPos,x%id%,y%id%,w%id%,h%id%,A
String := GetCurrentMonitor(x%id%,y%id%,w%id%,h%id%)
Array := StrSplit(String, A_Space)
MonitorX := Array[1]
MonitorY := Array[2]
MonitorW := Array[3]
MonitorH := Array[4]
CenterX := Array[5]
CenterY := Array[6]
if(x%id%+w%id%/2 < CenterX){
;左
WinMove,ahk_id %id%,,MonitorX,MonitorY+4
,MonitorW/2,MonitorH
}
Else{
;右
WinMove,ahk_id %id%,,CenterX,MonitorY+4
,MonitorW/2,MonitorH
}
}
Else{
;元のポジションに戻してウィンドウを忘れる
WinMove,ahk_id %id%,,x%id%,y%id%,w%id%,h%id%
x%id%=
y%id%=
w%id%=
y%id%=
}
return
^+!k::
WinGet,id,ID,A
if(x%id%=""){
WinGetPos,x%id%,y%id%,w%id%,h%id%,A
String := GetCurrentMonitor(x%id%,y%id%,w%id%,h%id%)
Array := StrSplit(String, A_Space)
MonitorX := Array[1]
MonitorY := Array[2]
MonitorW := Array[3]
MonitorH := Array[4]
CenterX := Array[5]
CenterY := Array[6]
if(y%id%+h%id%/2 < CenterY){
;上
WinMove,ahk_id %id%,,MonitorX,MonitorY+4
,MonitorW,MonitorH/2
}
Else{
;下
WinMove,ahk_id %id%,,MonitorX,CenterY+4
,MonitorW,MonitorH/2
}
}
Else{
;元のポジションに戻してウィンドウを忘れる
WinMove,ahk_id %id%,,x%id%,y%id%,w%id%,h%id%
x%id%=
y%id%=
w%id%=
y%id%=
}
return
^+!j::
WinGet,id,ID,A
if(x%id%=""){
WinGetPos,x%id%,y%id%,w%id%,h%id%,A
String := GetCurrentMonitor(x%id%,y%id%,w%id%,h%id%)
Array := StrSplit(String, A_Space)
MonitorX := Array[1]
MonitorY := Array[2]
MonitorW := Array[3]
MonitorH := Array[4]
CenterX := Array[5]
CenterY := Array[6]
WinMove,ahk_id %id%,,MonitorX,MonitorY+4
,MonitorW,MonitorH
}
Else{
;元のポジションに戻してウィンドウを忘れる
WinMove,ahk_id %id%,,x%id%,y%id%,w%id%,h%id%
x%id%=
y%id%=
w%id%=
y%id%=
}
return
^+!Left::
WinGet,id,ID,A
if(x%id%=""){
WinGetPos,x%id%,y%id%,w%id%,h%id%,A
}
String := GetCurrentMonitor(x%id%,y%id%,w%id%,h%id%)
Array := StrSplit(String, A_Space)
MonitorX := Array[1]
MonitorY := Array[2]
MonitorW := Array[3]
MonitorH := Array[4]
CenterX := Array[5]
CenterY := Array[6]
;左
WinMove,ahk_id %id%,,MonitorX,MonitorY+4
,MonitorW/2,MonitorH
return
^+!Right::
WinGet,id,ID,A
if(x%id%=""){
WinGetPos,x%id%,y%id%,w%id%,h%id%,A
}
String := GetCurrentMonitor(x%id%,y%id%,w%id%,h%id%)
Array := StrSplit(String, A_Space)
MonitorX := Array[1]
MonitorY := Array[2]
MonitorW := Array[3]
MonitorH := Array[4]
CenterX := Array[5]
CenterY := Array[6]
;右
WinMove,ahk_id %id%,,CenterX,MonitorY+4
,MonitorW/2,MonitorH
return
^+!UP::
WinGet,id,ID,A
if(x%id%=""){
WinGetPos,x%id%,y%id%,w%id%,h%id%,A
}
String := GetCurrentMonitor(x%id%,y%id%,w%id%,h%id%)
Array := StrSplit(String, A_Space)
MonitorX := Array[1]
MonitorY := Array[2]
MonitorW := Array[3]
MonitorH := Array[4]
CenterX := Array[5]
CenterY := Array[6]
;上
WinMove,ahk_id %id%,,MonitorX,MonitorY+4
,MonitorW,MonitorH/2
return
^+!DOWN::
WinGet,id,ID,A
if(x%id%=""){
WinGetPos,x%id%,y%id%,w%id%,h%id%,A
}
String := GetCurrentMonitor(x%id%,y%id%,w%id%,h%id%)
Array := StrSplit(String, A_Space)
MonitorX := Array[1]
MonitorY := Array[2]
MonitorW := Array[3]
MonitorH := Array[4]
CenterX := Array[5]
CenterY := Array[6]
WinMove,ahk_id %id%,,MonitorX,CenterY+4
,MonitorW,MonitorH/2
return
;拡張デスクトップの切り替え
^Left::#^Left
^Right::#^Right
^Up::#^Left
^Down::#^Right
以前のスクリプトでは画面サイズをハードコーディングしていたが、自動取得するAPIを発見したため、それに変更してみた。
あと、ウィンドウの移動とサイズ変更方法をWindowsの「Winキー+矢印」っぽくしてみた。使用方法は以下。
Ctrl+Shift+Alt+i | ウィンドウ縦拡大 |
Ctrl+Shift+Alt+k | ウィンドウ横拡大 |
Ctrl+Shift+Alt+j | ウィンドウ全画面 |
Ctrl+Shift+Alt+← | ウィンドウ左寄せ |
Ctrl+Shift+Alt+→ | ウィンドウ右寄せ |
Ctrl+Shift+Alt+↑ | ウィンドウ上寄せ |
Ctrl+Shift+Alt+↓ | ウィンドウ下寄せ |
Ctrl+← | 仮想デスクトップ切り替え左 |
Ctrl+→ | 仮想デスクトップ切り替え右 |
Ctrl+↑ | 仮想デスクトップ切り替え左 |
Ctrl+↓ | 仮想デスクトップ切り替え右 |
拡大中のウィンドウ選択時に特定のショートカットを入力すると元のサイズと位置に戻る。
あと、拡張デスクトップの切り替えをCtrl+矢印でできようにホットキーを変更している。
マルチモニターには一応対応させてつもり。誤動作するかもしれません。ご注意を。スクリプトの文字コードはUTF-8にしてください。