把图存在AU3脚本里论坛里有,但是如何把图存在Au3脚本里,同时还可以响应事件?
如附件,这里编写了一个可以通过上下左右方向键移动图片的脚本,不想带着jpg图片了,想保存在Au3脚本的二进制数里(这个论坛里有例子了),存在Au3脚本里如何还能响应键盘事件,从而改变图片的位置?
整个工程见附件
代码如下:#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
Global $hHook, $hStub_KeyProc
Global $g_iPlaneLeft = 200
Global $g_iPlaneTop = 200
Global $g_iSpeed = 2
#Region ### START Koda GUI section ### Form=D:\prj\Au3\koda_1.7.3.0\Forms\mb\GameMan30.kxf
$frmMain = GUICreate("方向键移动飞机的位置", 400, 300, 192, 124)
GUISetBkColor(0x000000)
$pic_Plane = GUICtrlCreatePic("Plane.JPG", $g_iPlaneLeft, $g_iPlaneTop, 14, 13)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
OnAutoItExitRegister("Cleanup")
$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case Else
;
EndSwitch
; 刷新Plane位置
GUICtrlSetPos($pic_Plane, $g_iPlaneLeft, $g_iPlaneTop)
;Sleep(10)
WEnd
; ===========================================================
; 按键分支 Up Down Left Right方向键
; ===========================================================
Func EvaluateKey($keycode)
If ($keycode = 27) Then ; esc key
Exit
ElseIf ($keycode = 0x25) Then ; Left key
$g_iPlaneLeft = $g_iPlaneLeft - $g_iSpeed
;ConsoleWrite("Left" & @CRLF)
ElseIf ($keycode = 0x26) Then ; Up key
$g_iPlaneTop = $g_iPlaneTop - $g_iSpeed
;ConsoleWrite("Up" & @CRLF)
ElseIf ($keycode = 0x27) Then ; Right key
$g_iPlaneLeft = $g_iPlaneLeft + $g_iSpeed
;ConsoleWrite("Right" & @CRLF)
ElseIf ($keycode = 0x28) Then ; LEFT key
$g_iPlaneTop = $g_iPlaneTop + $g_iSpeed
;ConsoleWrite("Down" & @CRLF)
Else
;
EndIf
EndFunc ;==>EvaluateKey
; ===========================================================
; 回调函数
; ===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
Local $tKEYHOOKS
$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndIf
;---> 如果是KeyDown事件 ($WM_KEYDOWN = 256, $WM_KEYUP = 257)
If $wParam = $WM_KEYDOWN Then
EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
EndIf
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
Func Cleanup()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
EndFunc ;==>Cleanup
|