#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <Misc.au3>

;Opt("TrayIconHide", 1)
;Opt("WinTitleMatchMode", 2)
OnAutoItExitRegister("_Exit")
$user_dll = DllOpen("user32.dll")

$pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
$hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)
_Main()

Func _Main()

	Local $GUI, $coords[4]

	While 1
		$coords = WinGetPos($GUI)
		_MouseTrap($coords[0], $coords[1], $coords[0] + $coords[2], $coords[1] + $coords[3])
	WEnd
	_MouseTrap()
	Exit
EndFunc


Func _KeyProc($nCode, $wParam, $lParam)

If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
    Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    Local $vkCode = DllStructGetData($tKEYHOOKS, "vkCode")

If ($wParam = $WM_KEYDOWN) And $vkCode <>  0x77 Then
        DllCall($user_dll, 'int', 'keybd_event', 'int', 0x0, 'int', 0, 'int', 0, 'ptr', 0)
        Return -1
    EndIf
    Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
EndFunc

