 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Leon
Joined: 27 Aug 2007 Posts: 179
|
Posted: Thu May 22, 2008 12:47 am Post subject: Need help with OnMessage |
|
|
hi,
The first 2 pieces of code work fine individually (in separate scripts) but combining them to one script doesn't work.
How can I get both OnMessage commands to work in the 3rd script?
I tried following the example in docs which uses two OnMessage commands but couldn't get it to work.
Script_1 detects user mouse moves in the gui window.
Script_2 detects user mouse clicks in the gui window.
Script_3 should detect both but doesn't.
| Code: | ;Script_1
#InstallKeybdHook
#InstallMouseHook
Gui +AlwaysonTop +LastFound +Toolwindow
Gui, Show, w400 h300, SemiSeeThru
WinSet, Transparent, 50, SemiSeeThru
OnMessage(0x200, "Lift")
Return
Lift()
{
ToolTip, %A_TimeIdlePhysical%
}
^r::reload
#End::ExitApp |
| Code: | ;Script_2
#InstallKeybdHook
#InstallMouseHook
Gui +AlwaysOnTop +LastFound +Toolwindow
Gui, Show, w400 h300, SemiSeeThru
WinSet, Transparent, 50, SemiSeeThru
OnMessage(0x201, "WM_LBUTTONDOWN")
Return
WM_LBUTTONDOWN(wParam, lParam)
{
X := lParam & 0xFFFF
Y := lParam >> 16
ToolTip Clicked at %X%`, %Y%
}
^r::reload
#End::ExitApp
|
| Code: | ;Script_3
#InstallKeybdHook
#InstallMouseHook
Gui +AlwaysOnTop +LastFound +Toolwindow
Gui, Show, w400 h300, SemiSeeThru
WinSet, Transparent, 50, SemiSeeThru
OnMessage(0x201, "WM_LBUTTONDOWN")
Return
OnMessage(0x200, "Lift")
Return
WM_LBUTTONDOWN(wParam, lParam)
{
X := lParam & 0xFFFF
Y := lParam >> 16
ToolTip Clicked at %X%`, %Y%
}
Lift()
{
ToolTip, %A_TimeIdlePhysical%
}
^r::reload
#End::ExitApp
|
|
|
| Back to top |
|
 |
Zippo() Guest
|
Posted: Thu May 22, 2008 7:47 am Post subject: |
|
|
You need to take out the return in the 3rd script before the second OnMessage or it never gets executed.
| Code: | ;Script_3
#InstallKeybdHook
#InstallMouseHook
Gui +AlwaysOnTop +LastFound +Toolwindow
Gui, Show, w400 h300, SemiSeeThru
WinSet, Transparent, 50, SemiSeeThru
OnMessage(0x201, "WM_LBUTTONDOWN")
;Return
OnMessage(0x200, "Lift")
Return
WM_LBUTTONDOWN(wParam, lParam)
{
X := lParam & 0xFFFF
Y := lParam >> 16
ToolTip Clicked at %X%`, %Y%
}
Lift()
{
ToolTip, %A_TimeIdlePhysical%
}
^r::reload
#End::ExitApp |
|
|
| Back to top |
|
 |
Leon
Joined: 27 Aug 2007 Posts: 179
|
Posted: Thu May 22, 2008 2:41 pm Post subject: |
|
|
| Zippo() wrote: | | You need to take out the return in the 3rd script before the second OnMessage or it never gets executed. |
That doesn't work either. It only detects mouse moves but not clicks.
This new code below, almost works. It detects clicks and moves
But when moves are detected the tooltip keeps updating itself like a loop.
Clicking interupts the "loop" and moving again restarts "looping"
But I can't find what is causing that behaviour.
| Code: | ;Script_3
#InstallKeybdHook
#InstallMouseHook
Gui +AlwaysOnTop +LastFound +Toolwindow
Gui, Show, w400 h300, SemiSeeThru
WinSet, Transparent, 50, SemiSeeThru
OnMessage(0x201, "WM_LBUTTONDOWN")
;Return
OnMessage(0x200, "Lift") ;moving to line7 doesn't prevent "looping" behaviour.
Return
WM_LBUTTONDOWN(wParam, lParam)
{
X := lParam & 0xFFFF
Y := lParam >> 16
ToolTip Clicked at %X%`, %Y%
;removing next 2 lines = clicking interrupts looping temporarily instead of permenantly
Sleep 1000
Tooltip
}
return ;removing doesn't prevent "looping" behaviour.
Lift()
{
ToolTip, %A_TimeIdlePhysical%
Sleep 1000 ;removing this and next line causes strange behaviour
Tooltip
}
return ;removing doesn't prevent "looping" behaviour.
^r::reload
#End::ExitApp |
|
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Thu May 22, 2008 2:57 pm Post subject: |
|
|
the "looping" behavior is caused by the fact that WM_MOUSEMOVE is called like a gazillion times when you move over the gui.
you can test with this:
| Code: | Lift(){
global Count
Count++
}
#a::MsgBox % Count
|
you definitely do not want a sleep in the message handler function. _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Thu May 22, 2008 3:12 pm Post subject: |
|
|
Here is a script that monitors both:
| Code: | ;Script_3
#InstallKeybdHook
#InstallMouseHook
WM_LBUTTONDOWN := 0x201
WM_MOUSEMOVE := 0x200
Gui +AlwaysOnTop +LastFound +Toolwindow
Gui, Add, Edit, vConsole h250 w300
Gui, Show, w400 h300, SemiSeeThru
;WinSet, Transparent, 50, SemiSeeThru
OnMessage(WM_LBUTTONDOWN, "MyMessageMonitor")
OnMessage(WM_MOUSEMOVE, "MyMessageMonitor")
Return
MyMessageMonitor(wParam, lParam, msg, hwnd) {
global WM_LBUTTONDOWN, WM_MOUSEMOVE
global WM_LBUTTONDOWN_Count, WM_MOUSEMOVE_Count, Console
if (msg = WM_LBUTTONDOWN) {
WM_LBUTTONDOWN_Count++
X := lParam & 0xFFFF
Y := lParam >> 16
Console = WM_LBUTTONDOWN [%WM_LBUTTONDOWN_Count%] (Clicked at %X%`, %Y%)`n%Console%
GuiControl, , Console, %Console%
}
Else if (msg = WM_MOUSEMOVE){
WM_MOUSEMOVE_Count++
X := lParam & 0xFFFF
Y := lParam >> 16
Console = WM_MOUSEMOVE [%WM_MOUSEMOVE_Count%] (Mouse at %X%`, %Y%)`n%Console%
GuiControl, , Console, %Console%
}
}
^r::reload
Esc::ExitApp |
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Thu May 22, 2008 3:19 pm Post subject: |
|
|
funny it does not receive either message when the mouse is over the scrollbar. _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|