AutoHotkey Community

It is currently May 26th, 2012, 7:14 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Need help with OnMessage
PostPosted: May 22nd, 2008, 1:47 am 
Offline

Joined: August 27th, 2007, 8:00 pm
Posts: 179
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 8:47 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 3:41 pm 
Offline

Joined: August 27th, 2007, 8:00 pm
Posts: 179
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 3:57 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
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.

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 4:12 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
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

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 4:19 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
funny it does not receive either message when the mouse is over the scrollbar.

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], bobbysoon, kkkddd1 and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group