Sign in to follow this  
Followers 0
jayr2

GuiRegisterMsg Help

2 posts in this topic

I'm having a heck of a time figuring this one out. I'm trying to create a refresh key (think F5 in IE) within a script i'm writing. I'm aware of the HotKeySet function, but this registers the hokey at the OS level, i only want my refresh function to run when my app is the active app. I suppose i could use HotKeySet and in the function check to see if i'm the active app, but i thought GuiRegisterMsg would be a better way to do this. So i tried to register the WM_KEYDOWN message, and inside my function i figured i'd check what key was pressed. If F5 was pressed, run my refresh, otherwise exit the function. The problem is i can't seem to get it to work. Here's a little script to show what i'm doing:

#include <GUIConstants.au3>
#include <Date.au3>

CONST $WM_KEYDOWN = 0x0100
CONST $WM_SYSKEYDOWN = 0x0104 
CONST $WM_RBUTTONDOWN = 0x0204

$Form1 = GUICreate("Test", 151, 55, @DesktopWidth/2 - 75, @DesktopHeight/2 - 27)
$Label1 = GUICtrlCreateLabel("", 16, 16, 115, 17, BitOR($SS_CENTER,$SS_SUNKEN))
GUICtrlSetData($label1, _Now())

GUIRegisterMsg($WM_RBUTTONDOWN, "MY_WM_RBUTTONDOWN")
GUIRegisterMsg($WM_SYSKEYDOWN, "MY_WM_SYSKEYDOWN")
GUIRegisterMsg($WM_KEYDOWN, "MY_WM_KEYDOWN")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func MY_WM_KEYDOWN($hWndGUI, $MsgID, $WParam, $LParam)
    ; IN THE FUTURE CHECK THE KEY PRESSED, IF IT'S NOT F5 DO NOTHING
    GUICtrlSetData($label1, _Now())
EndFunc

Func MY_WM_RBUTTONDOWN($hWndGUI, $MsgID, $WParam, $LParam)
    GUICtrlSetData($label1, _Now())
EndFunc

Func MY_WM_SYSKEYDOWN($hWndGUI, $MsgID, $WParam, $LParam)
    GUICtrlSetData($label1, _Now())
EndFunc

i know i'm using the GuiRegisterMsg function correctly because the MY_WM_RBUTTONDOWN function gets called if you right click the window (which means my functions are also written correctly). I know the WM_SYSKEYDOWN message is for system keys such as Alt and Ctrl, but i figured i'd try it anyway. I've also tried the WM_KEYUP message. No matter what my app never seems to respond to keypresses.

Not sure what i'm doing wrong; wrong message, wrong hex value????

I'm running:

WinXP SP2

Autoit 3.2.2.0

Full/latest version of SciTE (i've tried running my script inside of SciTE and outside of SciTE; same result)

let me know if more info is need.

Thanks

Share this post


Link to post
Share on other sites



You can try _IsPressed function like as below.

#include <GUIConstants.au3>
#include <Date.au3>
#Include <Misc.au3>

$dll = DllOpen("user32.dll")
$Form1 = GUICreate("Test", 151, 55, @DesktopWidth/2 - 75, @DesktopHeight/2 - 27)
$Label1 = GUICtrlCreateLabel("", 0, 10, 130, 17, BitOR($SS_CENTER,$SS_SUNKEN))
GUICtrlSetData($label1, _Now())
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $GUI_EVENT_SECONDARYUP Or _IsPressed("74", $dll)
            GUICtrlSetData($label1, _Now())
    EndSelect
WEnd

DllClose($dll)
GUIDelete()
Exit

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