Тема: AHK: Тест гуи в портретном режиме монитора
Понадобилось написать гуи для портретного режима монитора.
Переворачивать монитор взад-вперед неохота - написал скрипт.
По f11 идет переключение режимов.
При нажатии esc переходит в режим альбома.
#SingleInstance, Force
OnExit, RemoveHook
Global prevX, prevY
VarSetCapacity(DEVMODE, 220, 0)
NumPut(220, DEVMODE, 68, "short") ; dmSize
DllCall("EnumDisplaySettingsW", "ptr", 0, "int", -1, "ptr", &DEVMODE)
width := NumGet(DEVMODE, 172, "uint")
height := NumGet(DEVMODE, 176, "uint")
f11::
if !hHookMouse
{
NumPut(width, DEVMODE, 176, "int")
NumPut(height, DEVMODE, 172, "int")
NumPut(DMDO_90 := 1, DEVMODE, 84, "int") ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)
hHookMouse := DllCall("SetWindowsHookEx", "int", WH_MOUSE_LL := 14, "ptr", RegisterCallback("WH_MOUSE_LL", "Fast"), "ptr", DllCall("GetModuleHandle", "uint", 0, "ptr"), "uint", 0, "ptr")
}
else
GoSub, RemoveHook
return
esc::
GoSub, RemoveHook
return
RemoveHook:
if hHookMouse
{
DllCall("UnhookWindowsHookEx", "ptr", hHookMouse)
NumPut(width, DEVMODE, 172, "int")
NumPut(height, DEVMODE, 176, "int")
NumPut(DMDO_DEFAULT := 0, DEVMODE, 84, "int") ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)
prevX := prevY := hHookMouse := ""
}
if A_ExitReason
ExitApp
return
WH_MOUSE_LL(nCode, wParam, lParam)
{
Critical
if !nCode && (wParam = 0x200) ; WM_MOUSEMOVE
{
x := NumGet(lParam+0, 0, "int") ; x-coord
y := NumGet(lParam+0, 4, "int") ; y-coord
if (prevX = "")
prevX := x
if (prevY = "")
prevY := y
newX := prevX - y + prevY
newY := prevY + x - prevX
DllCall("SetCursorPos", "int", newX, "int", newY)
VarSetCapacity(lpPoint, 8)
DllCall("GetCursorPos", "ptr", &lpPoint)
prevX := NumGet(lpPoint, 0, "int")
prevY := NumGet(lpPoint, 4, "int")
NumPut(newX, lParam+0, 0, "int")
NumPut(newY, lParam+0, 4, "int")
DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "int", wParam, "ptr", lParam)
return 1
}
else
return DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "int", wParam, "ptr", lParam)
}