Sign in to follow this  
Followers 0
JosephE

Trapping WM_CHAR

6 posts in this topic

Ok, so i have this code:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>


; Test

Global $myGui = GUICreate("Hello", 500, 400)

GUIRegisterMsg($WM_CHAR, "HandleChar")

GUISetState(@SW_SHOW, $myGui)

While True
  $msg = GuiGetMsg()
  If $msg = $GUI_EVENT_CLOSE Then
    ExitLoop
  EndIf
WEnd

Func HandleChar($hWnd, $msgID, $wParam, $lParam)
  MsgBox(0, "Handled!", "It was handled. Character code: " & $wParam)
EndFunc

There's no edit control, so the WM_CHAR message should cause the HandleChar() function to be called, but it's not. I need to be able to handle that message, as I need a way of handling key presses for my custom text widget I'm rendering in GDI+.

Any help would be very much appreciated! :)

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

I'm well aware of that, but i do not have an edit control present in my window. Obviously.

Share this post


Link to post
Share on other sites

Same problem here! WM_Char is not working :mellow:

but WM_KEYDOWN does:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGui = GUICreate("Test", 500, 400)
GUIRegisterMsg($WM_KEYDOWN, "WM_KEYDOWN")
GUISetState(@SW_SHOW, $hGui)

While True
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
WEnd

Func WM_KEYDOWN($hWnd, $msg, $wParam, $lParam)
    Local $uScancode = BitAND(BitShift($lParam, 16), 0xFF)

    Local $tData = DllStructCreate("byte[256];")
    Local $pData = DllStructGetPtr($tData)
    Local $aResult = DllCall("user32.dll", "int", "GetKeyboardState", "ptr", $pData)

    Local $tChar = DllStructCreate("char[2];")
    Local $pChar = DllStructGetPtr($tChar)
    $aResult = DllCall("user32.dll", "int", "ToAscii", "uint", $wParam, "uint", $uScancode, "ptr", $pData, "ptr", $pChar, "uint", 0)
    If @error Then Return 'GUI_RUNDEFMSG'

    If $aResult[0] > 0 Then ConsoleWrite("! <" & DllStructGetData($tChar, 1) & ">" & @CRLF)

    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_KEYDOWN

Share this post


Link to post
Share on other sites

but WM_KEYUP works with all cases.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0