Skip to content

Instantly share code, notes, and snippets.

@hetima
Last active December 4, 2021 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hetima/f214ae473d31887549e57f76d582e8c1 to your computer and use it in GitHub Desktop.
Save hetima/f214ae473d31887549e57f76d582e8c1 to your computer and use it in GitHub Desktop.
キーを押しながらマウスを動かすとズームやスクロールができるahk
; #InstallKeybdHook や #InstallMouseHook が必要かもしれない
/*
MouseMoveObsvr をサブクラス化して
F2::new SubMouseMoveObsvr("F2")
というようにして使う
キーを押したままマウスを動かすと onLeft() onRight() onUp() onDown() が呼ばれる
マウスが動かさずキーを離したとき(空打ち)は emptyHit() が呼ばれる
xDistance := 8 / yDistance := 8 このピクセル数マウスが動くごとに呼ばれる
xInitialDistance := 16 / yInitialDistance := 16 動かし始めだけはこっちが基準
作動中はマウスカーソルの位置を固定して、終了時に移動した量を反映させるので見た目はあまり良くないが、
前者はスクロールさせたい場所から離れないようにするため、後者は手元とカーソルの位置がずれないようにするためにこうなっている
fixedPosition := True にしておくと終了時に移動しない
*/
Class MouseMoveObsvr {
xDistance := 8
yDistance := 8
xInitialDistance := 16
yInitialDistance := 16
ox := 0
oy := 0
fixedPosition := False
__New(triggerKey, interval=50) {
if (this.observe(triggerKey, interval) != True) {
this.emptyHit()
}
}
observe(triggerKey, interval=50) {
result := False
MouseGetPos, ox, oy
this.ox := ox
this.oy := oy
dxTotal := 0
dyTotal := 0
dxRemain := 0
dyRemain := 0
this.onInit()
While GetKeyState(triggerKey, "P") = 1 {
Sleep, interval
MouseGetPos, x, y
dx := x-ox+dxRemain
dy := y-oy+dyRemain
if (dx > this.xDistance and dx > this.xInitialDistance) {
this.onRight()
;ox := x
this.xInitialDistance := this.xDistance
dxRemain := 0
result := True
} else if(dx < 0-this.xDistance and dx < 0-this.xInitialDistance) {
this.onLeft()
;ox := x
this.xInitialDistance := this.xDistance
dxRemain := 0
result := True
} else {
dxRemain := dx
}
if (dy > this.yDistance and dy > this.yInitialDistance) {
this.onDown()
;oy := y
this.yInitialDistance := this.yDistance
dyRemain := 0
result := True
} else if (dy < 0-this.yDistance and dy < 0-this.yInitialDistance) {
this.onUp()
;oy := y
this.yInitialDistance := this.yDistance
dyRemain := 0
result := True
} else {
dyRemain := dy
}
dxTotal := dxTotal + x-ox
dyTotal := dyTotal + y-oy
MouseMove ox, oy, 0
}
if(!this.fixedPosition){
MouseMove ox+dxTotal, oy+dyTotal, 2
}
Return result
}
onInit(){
}
onLeft(){
}
onRight(){
}
onUp(){
}
onDown(){
}
emptyHit(){
}
; __delete(){
; ; msgbox delete
; }
}
; example
class Default_MouseMoveObsvr extends MouseMoveObsvr{
xDistance := 2
yDistance := 2
xInitialDistance := 8
yInitialDistance := 8
fixedPosition := False
onLeft(){
Send, {LShift Down}{WheelUp 1}{LShift Up}
}
onRight(){
Send, {LShift Down}{WheelDown 1}{LShift Up}
}
onUp(){ ;
Send, {WheelUp 1}
}
onDown(){ ;
Send, {WheelDown 1}
}
emptyHit(){
Send, {F2}
}
}
F2::new Default_MouseMoveObsvr("F2")
; Cubase
#IfWinActive ahk_exe Cubase11.exe
class Cubase_MouseMoveObsvr extends MouseMoveObsvr{
xDistance := 16
yDistance := 24
doLeft(){
Send, {LShift Down}{WheelDown 2}{LShift Up}
}
doRight(){
Send, {LShift Down}{WheelUp 2}{LShift Up}
}
doUp(){ ;縮小
Send, G
}
doDown(){ ;拡大
Send, H
}
}
F2::new Cubase_MouseMoveObsvr("F2")
#IfWinActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment