• 追加された行はこの色です。
  • 削除された行はこの色です。
#author("2023-06-07T13:36:52+09:00","default:ryuichi","ryuichi")
 Menu, Tray, Icon, images\ahk-remote-desktop.ico
 
 ; Readline apps
 GroupAdd, Grp1, ahk_class mintty
 GroupAdd, Grp1, ahk_class ConsoleWindowClass ; CMD
 GroupAdd, Grp1, Windows PowerShell ISE
 GroupAdd, Grp1, ahk_class HwndWrapper\[DefaultDomain;;[\da-f\-]+] ; VS
 GroupAdd, Grp1, ahk_class Vim
 GroupAdd, Grp1, ahk_exe Code.exe
 GroupAdd, Grp1, ahk_exe Console.exe
 GroupAdd, Grp1, ahk_exe WindowsTerminal.exe
 
 ; Delete a word with backspace
 GroupAdd, Grp2, - Mery$ ahk_class TChildForm ; Mery
 GroupAdd, Grp2, ahk_class CabinetWClass      ; Explorer
 GroupAdd, Grp2, ahk_class Notepad            ; Notepad
 
 Capslock::Ctrl
 
 !^F24::Send #{Right}
 !^F23::Send #{Left}
 !^F22::Send +#{Up}
 !^F21::Send #{Up}
 !^F15::Send #r
 +^F15::Send #s
 +^F24::WindowWidthIncrese()
 +^F23::WindowWidthDecrese()
 +^F22::WindowHeightIncrese()
 +^F21::WindowHeightDecrese()
 ^F24::WindowMoveToXDirection("right")
 ^F23::WindowMoveToXDirection("left")
 ^F22::WindowMoveToXDirection("down")
 ^F21::WindowMoveToXDirection("up")
 !^F19::WindowMoveToCenter()
 LAlt & PgUp::AltTab
 
 ^+F20::Send !{F4}
 ; +^F21::
 ;   WinGetPos, X, Y, W, H, A
 ;   _W := W + Floor(A_ScreenWidth / 7)
 ;   if (X + _W < A_ScreenWidth) {
 ;     WinMove, A, , , , _W
 ;     Send +#{Up}
 ;   } else {
 ;     Send #{Up}
 ;   }
 ;   Return
 
 ^+F13::IME_SET(0)
 ^+F14::IME_SET(1)
 <!Space::IME_SET(0) ; for using this PC on not remote-desktop
 >!Space::IME_SET(1) ; for using this PC on not remote-desktop
 IME_SET(SetSts, WinTitle="A") {
   ControlGet,hwnd,HWND,,,%WinTitle%
   if  (WinActive(WinTitle))  {
     ptrSize := !A_PtrSize ? 4 : A_PtrSize
       VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
       NumPut(cbSize, stGTI,  0, "UInt")   ;  DWORD   cbSize;
     hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint,&stGTI)
                ? NumGet(stGTI,8+PtrSize,"UInt") : hwnd
   }
   return DllCall("SendMessage"
     , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hwnd)
     , UInt, 0x0283  ;Message : WM_IME_CONTROL
     ,  Int, 0x006   ;wParam  : IMC_SETOPENSTATUS
     ,  Int, SetSts) ;lParam  : 0 or 1
 }
 
 MButton Up::
   if (WinExist("ahk_exe Magnify.exe")) {
     Send #{ESC}
   } else {
     Send #=
   }
   Return
 
 !q::
 !^F20:: ; Via RemoteDesktop
   if (WinActive("ahk_exe chrome.exe") || WinActive("ahk_exe msedge.exe")) {
     Send ^w
   } else if (WinActive("ahk_exe code.exe")) {
     Send, ^{F4}
   } else {
     Send, !{F4}``
   }
   Return
 
 #IfWinActive ahk_exe Console.exe
 !l::Send, +{Home}{BackSpace}clear{Enter}
 !c::Send, ^{Ins}^{Delete}
 !v::Send, +{Ins}
 NumPadLeft:: Send, ^{PgDn}
 ; NumPadIns & Tab:: Send, ^{PageDown}
   ; Input, OutputVar, L1 T5 C
   ; If (OutputVar = "s") {
   ;   Send, ^+o
   ; } Else If (OutputVar = "|") {
   ;   Send, ^+e
   ; } Else If (OutputVar = "h") {
   ;   Sleep 50
   ;   Send ^{PageUp}
   ;   Sleep 50
   ; } Else If (OutputVar = "l"){
   ;   Sleep 50
   ;   Send ^{PageDown}
   ;   Sleep 50
   ; } Else If (OutputVar = "k"){
   ;   Sleep 50
   ;   Send ^{PageUp}
   ;   Sleep 50
   ; } Else If (OutputVar = "j"){
   ;   Sleep 50
   ;   Send ^{PageDown}
   ;   Sleep 50
   ; } Else If (OutputVar = "_"){
   ;   Sleep 50
   ;   Send !+{-}
   ;   Sleep 50
   ; } Else If (OutputVar = "="){
   ;   Sleep 50
   ;   Send !{=}
   ;   Sleep 50
   ; } Else If (OutputVar = "r"){
   ;   Sleep 50
   ;   Send !r
   ;   Sleep 50
   ; } Else {
   ;   SendInput %OutputVar%
   ; }
   ; Return
 #IfWinActive
 
 ; PowerShell/Cmd
 #IfWinActive ahk_class ConsoleWindowClass
 <+Ins::
 <!v::
   StringReplace, Clipboard2, Clipboard, `r`n, , All
   StringReplace, Clipboard2, Clipboard2, `n, , All
   StringReplace, Clipboard2, Clipboard2, `r, , All
   SendInput {Raw}%Clipboard2%
   Return
 <^Tab::
   WinGet, id, List, ahk_class ConsoleWindowClass
   Loop, %id%
   {
     StringTrimRight, this_id, id%A_Index%, 0
     WinGetClass, this_class, ahk_id %this_id%
     WinGetTitle, this_title, ahk_id %this_id%
     id_list%A_Index% = %this_id%
   }
   if (id >= 1 && id <= 4) {
       _id := id_list%id%
       WinActivate, ahk_id %_id%
   }
   Return
 #IfWinActive
 
 <!h::       Send {BS}                   ; Backspace
 <!m::       Send {Enter}                ; 改行
 <!d::       Send {Del}                  ; Del
 <!u::       Send +{Home}{BS}            ; 行頭まで削除
 <!+u::      Send +{Home}^x              ; 行頭までカット
 <!k::       Send +{End}{BS}             ; 行末まで削除
 <!+k::      Send +{End}^x               ; 行頭までカット
 <!a::       Send {HOME}                 ; 行頭へ移動
 <!+a::      Send +{HOME}                ; 行頭まで選択
 <!^a::      Send ^{HOME}                ; 先頭行へ移動
 <!e::       Send {END}                  ; 行末へ移動
 <!+e::      Send +{END}                 ; 行末まで選択
 <!^e::      Send ^{END}                 ; 最終行へ移動
 <!^p::      Send ^{HOME}                ; 先頭行まで移動
 <!^+p::     Send ^{HOME}                ; 先頭行まで選択
 <!^n::      Send ^{END}                 ; 最終行まで移動
 <!^+n::     Send ^+{END}                ; 最終行まで選択
 <!p::       Send {Up}                   ; 上へ移動
 <!n::       Send {Down}                 ; 下へ移動
 <!f::       SendInput {Right}           ; 右へ移動
 <!b::       SendInput {Left}            ; 左へ移動
 <!w::       Send +^{Left}{BS}           ; 直前の単語を削除
 <!^f::      Send ^{Right}               ; 1単語だけ右へ移動
 <!^b::      Send ^{Left}                ; 1単語だけ左へ移動
 
 #IfWinNotActive ahk_group Grp1
 <^h::       Send {BS}                   ; Backspace
 <^m::       Send {Enter}                ; 改行
 <^[::       Send {ESC}                  ; ESC
 <!o::       Send {End}{Enter}           ; 下に1行追加
 <+!o::      Send {Home}{Enter}{Up}      ; 上に1行追加
 <!y::       Send {Home}+{End}^c{End}    ; 1行コピー
 <!+y::      Send {Home}+{End}           ; 1行選択
 <!^y::      Send {Home}+{End}           ; 1行選択
 <+!{::      Send {Up 10}                ; 10行上へ移動
 <+!}::      Send {Down 10}              ; 10行下へ移動
 <!+(::      Send {PgUp}                 ; Page Up
 <!+)::      Send {PgDn}                 ; Page Down
 <^u::       Send +{Home}{Del}           ; 行頭まで削除
 <!Left::    Send {PgUp}                 ; Page Up
 <!Right::   Send {PgDn}                 ; Page Down
 <!Up::      Send ^{Home}                ; 先頭行まで移動
 <!Down::    Send ^{End}                 ; 最終行まで移動
 <!+Up::     Send +^{Home}               ; 先頭行まで選択
 <!+Down::   Send +^{End}                ; 最終行まで選択
 #IfWinNotActive
 
 #IfWinActive ahk_group Grp2
 <^BS:: Send +^{Left}{BS}
 #IfWinActive
 
 ; VSCode
 #IfWinActive ahk_exe Code.exe
 ^+F18::Send {F14} ; workbench.action.quickOpen
 #IfWinActive
 
 ; Zoom
 #IfWinActive, ahk_class ZPPTMainFrmWndClassEx 
 ~LButton::
 	CoordMode Mouse, Window
 	MouseGetPos MX, MY
   WinGetPos, WX, WY, WW, WH, A
   X := WW - MX 
   Y := MY
   if (X > 2 && X < 78 && Y > 2 && Y < 43) {
     Sleep, 200
     Loop {
       Process, Exist, zoom.exe
       If !ErrorLevel
         Break
       Process, Close, zoom.exe
     }
     Tray_Refresh()
     Return
   }
   Return
 #IfWinActive
 
 Tray_Refresh() {
 	WM_MOUSEMOVE := 0x200
 	detectHiddenWin := A_DetectHiddenWindows
 	DetectHiddenWindows, On
 
 	allTitles := ["ahk_class Shell_TrayWnd"
 			, "ahk_class NotifyIconOverflowWindow"]
 	allControls := ["ToolbarWindow321"
 				,"ToolbarWindow322"
 				,"ToolbarWindow323"
 				,"ToolbarWindow324"]
 	allIconSizes := [24,32]
 
 	for id, title in allTitles {
 		for id, controlName in allControls
 		{
 			for id, iconSize in allIconSizes
 			{
 				ControlGetPos, xTray,yTray,wdTray,htTray,% controlName,% title
 				y := htTray - 10
 				While (y > 0)
 				{
 					x := wdTray - iconSize/2
 					While (x > 0)
 					{
 						point := (y << 16) + x
 						PostMessage,% WM_MOUSEMOVE, 0,% point,% controlName,% title
 						x -= iconSize/2
 					}
 					y -= iconSize/2
 				}
 			}
 		}
 	}
 
 	DetectHiddenWindows, %detectHiddenWin%
 }
 
 WindowWidthIncrese() {
   MoveW := A_ScreenWidth / 10
   WinGetPos, X, Y, W, H, A
   if (X + W + MoveW + 5 < A_ScreenWidth) {
      WinMove, A, , , , W + MoveW
   } else {
      WinMove, A, , , , A_ScreenWidth - X - 5
   }
 }
 
 WindowWidthDecrese() {
   MoveW := A_ScreenWidth / 10
   MinimumW := A_ScreenWidth / 9
   WinGetPos, X, Y, W, H, A
   if (W - MoveW > MinimumW) {
      WinMove, A, , , , W - MoveW
   }
 }
 
 WindowHeightIncrese() {
   MoveH := A_ScreenHeight / 10
   WinGetPos, , , _w, _h, ahk_class Shell_TrayWnd ; Taskbar's height
   WinGetPos, X, Y, W, H, A
   if (Y + H + MoveH + 5 < A_ScreenHeight - _h) {
      WinMove, A, , , , , H + MoveH
   } else {
      WinMove, A, , , , , A_ScreenHeight - _h - Y - 5
   }
 }
 
 WindowHeightDecrese() {
   MoveH := A_ScreenHeight / 10
   MinimumH := A_ScreenHeight / 9
   WinGetPos, X, Y, W, H, A
   if (H - MoveH > MinimumH) {
      WinMove, A, , , , , H - MoveH
   }
 }
 
 WindowMoveToCenter()
 {
   WinGetPos, , , _w, _h, ahk_class Shell_TrayWnd ; Taskbar's height
   WinGetPos, X, Y, W, H, A
 
   WinL := X
   WinR := X + W
   WinT := Y
   WinB := Y + H
   MonL := 0
   MonR := A_ScreenWidth
   MonT := 0
   MonB := A_ScreenHeight
 
   HalfWinWidth := Floor((WinR - WinL) / 2)
   HalfMonWidth := Floor((MonR - MonL) / 2)
   NewWinX      := MonL + HalfMonWidth - HalfWinWidth
 
   HalfMonHeight := Floor((MonB - MonT - _h) / 2)
   HalfWinHeight := Floor((WinB - WinT) / 2)
   NewWinY       := MonT + HalfMonHeight - HalfWinHeight
 
   if ((NewWinX - MonL) < -15 || NewWinY - MonT < -15) {
     MsgBox, 48, % "WARNING", % "The window position of this app is bad. X:" . NewWinX . ", Y:" . NewWinY . ", MonL:" . MonL . ", MonT:" . MonT
     Return
   }
  
   WinMove, A, , NewWinX, NewWinY, ,
 }
 
 WindowMoveToXDirection(v)
 {
   WinGetPos, , , _w, _h, ahk_class Shell_TrayWnd ; Taskbar's height
   WinGetPos, X, Y, W, H, A
 
   MonH := A_ScreenHeight - _h
   MonW := A_ScreenWidth
   MonT := 0
   MonB := A_ScreenHeight - _h
   MonR := A_ScreenWidth
   MonL := 0
   MarginT := Y - 0
   MarginB := A_ScreenHeight - (Y + H)
   MarginL := X - 0
   MarginR := A_ScreenWidth - (X + W)
   Adjust := 0
 
   if (v = "up") {
     distance := MonH / 6
     if (distance > MarginT) {
       distance := MarginT
     }
     NewYPos := Y - distance
     if (MarginT < 15) {
       NewYPos := MonT
     }
   } else if (v = "down") {
     distance := MonH / 6
     if (distance > MarginB) {
       distance := MarginB
     }
     NewYPos := Y + distance
     if (NewYPos + H > MonB) {
       NewYPos := MonB - H
     }
   } else if (v = "left") {
     distance := MonW / 6
     if (distance > MarginL) {
       distance := MarginL
     }
     NewXPos := X - distance
     if (MarginL < 15) {
       NewXPos := MonL - Adjust
     }
   } else if (v = "right") {
     distance := MonW / 6
     if (distance > MarginR) {
       distance := MarginR + Adjust
     }
     NewXPos := X + distance
     if (MarginR < 15) {
       NewXPos := MonR - W + Adjust
     }
   } else {
     msgbox %v%
     Return
   }
 
   WinMove, A, , NewXPos, NewYPos
   ; msgbox % NewXPos
   ; msgbox %distance%
   ; msgbox % X
 } ; }}}
#author("2023-06-07T13:47:44+09:00","default:ryuichi","ryuichi")



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS