Jump to content
Sign in to follow this  
bestsmr

guiregistermsg

Recommended Posts

bestsmr

can some one explain why this codw do not work

*********

#include <WindowsConstants.au3>

#include <GUIConstantsEx.au3>

GUICreate("test")

GUICtrlCreateLabel("press character", 10, 10)

GUIRegisterMsg($WM_KEYDOWN, "keydown")

GUISetState()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then Exit

WEnd

Func keydown($hw, $msg, $wp, $lp)

MsgBox(0, "chr", "pressed")

EndFunc ;==>keydown

********************

but when i delet line **GUICtrlCreateLabel("press character", 10, 10)**

it works correctly

Share this post


Link to post
Share on other sites
martin

I think that as soon as you have controls on the form then the WM_KEYDOWN is redirected to them, so you need to use a Widows hook. Here is an example which is a modified from a version by ProgAndy

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


GUICreate("test")
GUICtrlCreateLabel("press character", 10, 10)

#region add windows hook
Global Const $ghcbKeyboardProc = DllCallbackRegister("_KeyboardProc", "lresult", "int;wparam;lparam")
Global Const $ghKeybordHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD, DllCallbackGetPtr($ghcbKeyboardProc), 0, _WinAPI_GetCurrentThreadId())
OnAutoItExitRegister("_gc")
#endregion add windows hook

GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd



Func _gc()
    _WinAPI_UnhookWindowsHookEx($ghcbKeyboardProc)
EndFunc   ;==>_gc



Func _KeyboardProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($ghKeybordHook, $nCode, $wParam, $lParam)

    Local $nVKeyCode = Number($wParam), $State = " DOWN"
    Local $fExtendedKey = BitAND($lParam, 2 ^ 24) <> 0;??
    Local $fKeyUp = BitAND($lParam, 2 ^ 31) <> 0
    Local $sKeyData

    if $fKeyUp then $State = " UP"
    $sKeyData = $nVKeyCode & ";" & $fExtendedKey & ";" & $State
    ConsoleWrite($sKeyData & @CRLF)


    ;  Return 0xDEAD ; kill the key event
    Return _WinAPI_CallNextHookEx($ghKeybordHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyboardProc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
bestsmr

ok , martin

thanks for code ; really it solve the problem . ;):D :D

but the truth " i could not undersand the code" :):D

can you answer me some question ????

1) why "_KeyboardProc" function was defined with three parametr ; I did not read in help file about that

2) how did you know that the first will be $ncode and second ......

I prefer to refer me to book or information source that can I read to teach :graduated: .... only to aviod you the tired of keyboard strokes when you write the answers . ;)

always thanks.

Share this post


Link to post
Share on other sites
martin

See here.

Book? What's that?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
bestsmr

ok ;

tooooooooooooooooooooooooooooooooooo thanks :graduated:;)

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  

×