That wasn't actually hard at all*. Here's an example based on Hedge Hunter v7 with the internal label subclassed so we can spy on $WM_KEYDOWN and $WM_KEYUP. I may include this in Hedge Engine later, then I should be able to use it for checking $WM_PAINT also, so I don't need to use GUIRegisterMsg().
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=n
;~ #AutoIt3Wrapper_Run_Debug_Mode=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.6.1
Author: Alexander Samuelsson (AdmiralAlkex)
Script Function:
Simple running game.
Credits:
UDF: AdmiralAlkex
Game-code: AdmiralAlkex
Graphics: AdmiralAlkex
Proving that GDI+wSDL is possible: monoceres
ToDo:
#ce ----------------------------------------------------------------------------
#Include "Hedge Engine.au3"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include "SDL_gfx.au3"
#include <Constants.au3>
$hGuiMain = GUICreate(StringTrimRight(@ScriptName, 4), 400, 330)
$hButton = GUICtrlCreateButton("Change rendering library", 5, 5, 150, 20)
GUISetState()
$pScreen = _HedgeInitRender
(1, $hGuiMain, 0, 30, 400, 300)
GUICtrlSetState(-1, $GUI_FOCUS) ;Give focus to the label used internally by Hedge
$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) ;Subclass the control
$iBackground = _HedgeAddAsset
(@ScriptDir & "\Graphics\BackgroundM.png")
Local $iWalk[2]
$iWalk[0] = _HedgeAddAsset
(@ScriptDir & "\Graphics\Walk1.png")
$iWalk[1] = _HedgeAddAsset
(@ScriptDir & "\Graphics\Walk2.png")
$iJump = _HedgeAddAsset
(@ScriptDir & "\Graphics\Jump.png")
Local $iTrap[3]
$iTrap[0] = _HedgeAddAsset
(@ScriptDir & "\Graphics\Spikes.png")
$iTrap[1] = _HedgeAddAsset
(@ScriptDir & "\Graphics\DeadCow.png")
$iTrap[2] = _HedgeAddAsset
(@ScriptDir & "\Graphics\SmallGuyWithSword.png")
$iFont = _HedgeAddAsset
(@ScriptDir & "\VeraMoBd.ttf", 18)
_SDL
_Startup
_gfx
()
$StructFPS = DllStructCreate($tagSDL_FPSmanager)
_SDL
_initFramerate
($StructFPS)
_SDL
_setFramerate
($StructFPS, 30)
WinSetTitle($hGuiMain, "", StringTrimRight(@ScriptName, 4) & " Rendering with: " & _HedgeGetRenderName
())
Local $iBackX = 0, $iUpTrue = False, $iTrapX = 0, $iTrap12 = 0
Global $Walk12 = 0
$pBack = _HedgeCreateSurface
(800, 300)
_HedgeBlit
($iBackground, $pBack, 0, 0, 800, 300, 0, 0)
_HedgeBlit
($iTrap[$iTrap12], $pBack, 0, 0, 100, 100, 400, 200)
AdlibRegister("_AniPlayer")
Local $iTimerJump = TimerInit()
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, $wProcOld)
Exit
Case $hButton
_WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, $wProcOld)
_ChangeRendering
()
GUICtrlSetState(-1, $GUI_FOCUS) ;Give focus to the label used internally by Hedge
$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
EndSwitch
_HedgeBlit
($pBack, $pScreen, $iBackX, 0, 400, 300, 0, 0)
If $iBackX >= 400 Then _HedgeBlit
($pBack, $pScreen, 0, 0, 400, 300, 800 - $iBackX, 0)
$iBackX += 6
If $iBackX >= 800 Then
$iBackX = 0
$iTrap12 += 1
If $iTrap12 > UBound($iTrap) -1 Then $iTrap12 = 0
_HedgeBlit
($iBackground, $pBack, 0, 0, 800, 300, 0, 0)
_HedgeBlit
($iTrap[$iTrap12], $pBack, 0, 0, 100, 100, 400, 200)
EndIf
If _Keys
(0x20) Then ;Used like _IsPressed!
If $iUpTrue = False And TimerDiff($iTimerJump) > 1500 Then
$iUpTrue = True
$iTimerJump = TimerInit()
_HedgeBlit
($iJump, $pScreen, 0, 0, 200, 200, 0, 0)
ElseIf $iUpTrue = True And TimerDiff($iTimerJump) < 500 Then
_HedgeBlit
($iJump, $pScreen, 0, 0, 200, 200, 0, 0)
Else
$iUpTrue = False
_HedgeBlit
($iWalk[$Walk12], $pScreen, 0, 0, 200, 200, 0, 100)
EndIf
Else
$iUpTrue = False
_HedgeBlit
($iWalk[$Walk12], $pScreen, 0, 0, 200, 200, 0, 100)
EndIf
_HedgeDrawText
($pScreen, $iFont, "$iBackX: " & $iBackX, 0xFF0000, 5, 5)
_HedgeFlip
()
If $iBackX > 300 And $iBackX < 340 And $iUpTrue = False Then
Sleep(1000)
_WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, $wProcOld)
Exit
EndIf
_SDL
_framerateDelay
($StructFPS)
WEnd
Func _AniPlayer
()
$Walk12 = Not $Walk12
EndFunc
Func _ChangeRendering
()
$iAmount = _HedgeGetRenderMax
()
$iCurrent = _HedgeGetRenderCurrent
()
$iCurrent += 1
If $iCurrent > $iAmount Then $iCurrent = 1
_HedgeChangeRender
($iCurrent)
_HedgeBlit
($iBackground, $pBack, 0, 0, 800, 300, 0, 0)
_HedgeBlit
($iTrap[$iTrap12], $pBack, 0, 0, 100, 100, 400, 200)
WinSetTitle($hGuiMain, "", StringTrimRight(@ScriptName, 4) & " Rendering with: " & _HedgeGetRenderName
())
EndFunc
Func _Keys
($iIndex, $iPressed = 2)
Static Local $aiKeys[256]
If @NumParams = 2 Then
$aiKeys[$iIndex] = $iPressed
Else
Return $aiKeys[$iIndex]
EndIf
EndFunc
Func _MyWindowProc
($hWnd, $uiMsg, $wParam, $lParam)
If $uiMsg = $WM_KEYDOWN Then
ConsoleWrite(1 & @LF)
_Keys
($wParam, 1)
ElseIf $uiMsg = $WM_KEYUP Then
ConsoleWrite(2 & @LF)
_Keys
($wParam, 0)
EndIf
;pass the unhandled messages to default WindowProc
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_MyWindowProc
*Well, I didn't spend get arrow keys to work, so I changed jump to Space.