AutoHotkey Community

It is currently May 27th, 2012, 10:52 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Advanced mouse functions
PostPosted: April 20th, 2004, 1:31 am 
:D I just had to post this script!

I initially used a couple of months making this work in C using Win32 API some years ago, but using AutoHotkey it just took a couple of hours!

It scrolls a window using the right and left mouse buttons. It works like a charm, but it would be smoother if cmallet would make the Send,{WheelUp} work.

It uses a mousehook and triggers on right mouse button down, checks where on the screen the click was, waits 200ms, checks which buttons are down and acts accordingly, loops until the right mouse is released, cheks which buttons are down and acts accordingly.

Skrommel

Code:
;STARTOFSCRIPT
; Scroll a window using the mouse
;
; Usage:
;
; Right click  = Right click
; Right hold and drag up = PageUp
; Right hold and drag down = PageDown
; Slow right click above middle of window = PageUp
; Slow right click below middle of window = PageDown
; Left hold and right click above middle of window = Top of page
; Left hold and right click below middle of window = Bottom of page
; Left hold and right hold above middle of window  = Previous page
; Left hold and right hold below middle of window  = Next page

SetWinDelay,0

$RButton::
SetEnv,moved,0
WinGetActiveStats,title,width,height,wx,wy
MouseGetPos,mx1,my1
EnvDiv,height,2
IfLess,my1,%height%
  SetEnv,scroll,U
Else
  SetEnv,scroll,D
Sleep,200

GetKeyState,lb,LButton,P
GetKeyState,rb,RButton,P
SetEnv,state,%lb%%rb%%scroll%
IfEqual,state,UDU
{
  SetEnv,splash,Up
  Gosub,SHOW
}
IfEqual,state,UDD
{
  SetEnv,splash,Down
  Gosub,SHOW
}
IfEqual,state,UUU
{
  MouseClick,RIGHT
  SetEnv,splash,RClick
  Gosub,SHOW
  Goto,END
}
IfEqual,state,UUD
{
  MouseClick,RIGHT
  SetEnv,splash,RClick
  Gosub,SHOW
  Goto,END
}
IfEqual,state,DUU
{
  MouseClick,left,,,,,U
  Send,^{Home}
  SetEnv,splash,Top
  Gosub,SHOW
  Goto,END
}
IfEqual,state,DUD
{
  MouseClick,left,,,,,U
  Send,^{End}
  SetEnv,splash,Bottom
  Gosub,SHOW
  Goto,END
}

MOVING:
Sleep,0
GetKeyState,lb,LButton,P
GetKeyState,rb,RButton,P
SetEnv,state,%lb%%rb%%scroll%
IfEqual,state,UUU
{
  IfEqual,moved,0
  {
    Send,{PgUp}
    SetEnv,splash,Up
    Gosub,SHOW
    Goto,END
  }
  Goto,END
}
IfEqual,state,UUD
{
  IfEqual,moved,0
  {
    Send,{PgDn}
    SetEnv,splash,Down
    Gosub,SHOW
    Goto,END
  }
  Goto,END
}
IfEqual,state,DDU
{
  MouseClick,left,,,,,U
  Send,{BROWSER_BACK}
  SetEnv,splash,Back
  Gosub,SHOW
  Goto,END
}
IfEqual,state,DDD
{
  MouseClick,left,,,,,U
  Send,{BROWSER_FORWARD}
  SetEnv,splash,Forward
  Gosub,SHOW
  Goto,END
}
MouseGetPos,mx2,my2
SetEnv,amounty,%my1%
EnvSub,amounty,%my2%
IfLess,amounty,-15
{
  SetEnv,my1,%my2%
  SetEnv,moved,1
  Send,{PgDn}
  SetEnv,splash,Down
  Gosub,SHOW
}
IfGreater,amounty,15
{
  SetEnv,my1,%my2%
  SetEnv,moved,1
  Send,{PgUp}
  SetEnv,splash,Up
  Gosub,SHOW
}
Goto,MOVING

SHOW:
WinGetActiveStats,title,width,height,wx,wy
MouseGetPos,mx3,my3
EnvAdd,mx3,%wx%
EnvAdd,my3,%wy%
EnvSub,mx3,60
SplashTextOn,50,0,%splash%
WinWait,%splash%
WinMove,%mx3%,%my3%
Return

END:
Sleep,400
SplashTextOff
Return
;ENDOFSCRIPT


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2004, 2:04 am 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
i'd problem with rt-clicking the tray icon of script & selecting exit...and strangely only with this script's icon :!:

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Me too
PostPosted: April 20th, 2004, 2:14 am 
:( I too have this problem exactly. Maybe cmallet knows?

Skrommel


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2004, 2:55 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Jeez, that script is amazing. Such imagination :)

Concerning the right mouse button not working quite right: I think I have an idea why; I'll look into it. In the meantime, you can right-click the icon then press X to exit the script.

Concerning "Send {WheelUp}": I will try to get this into the next release. Keep in mind that some people (such as myself) have changed their wheel so that each turn-increment goes up or down by an entire page, so it won't scroll as smoothly as intended in those cases.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Better
PostPosted: April 20th, 2004, 3:06 am 
But still better than Send,{PgUp}... :)
Isn't there a Window message SB_PAGEDOWN something, too? Hmmm.... Maybe another function, cmallet? Scroll,line|page|percentage,direction,amount,window,windowtext

Skrommel


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2004, 12:39 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I just tried a new technique and it seems to work with most windows. Your script may need a little adjusting in light of this, but give it a try.

Replace this first line with the next two (maybe in both places):
;Send,{PgUp}
ControlGetFocus, control, A
SendMessage, 0x115, 0, 0, %control%, A

And the same for this, except note that SendMessage uses a different 2nd parameter in this case:
;Send,{PgDn}
ControlGetFocus, control, A
SendMessage, 0x115, 1, 0, %control%, A


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Not for us simple minded
PostPosted: April 20th, 2004, 7:32 pm 
:) Yes, it works! SB_LINEUP and SB_LINEDOWN? But it's not very easy, is it? Where do you find the codes? Can you find the one for SB_PAGEUP and SB_PAGEDOWN?

And theres more:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/scrollbars/scrollbarreference/scrollbarmessages/wm_vscroll.asp

Skrommel


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2004, 7:40 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Yes, it's WM_VSCROLL and you can look up all such messages at MSDN (edit: you already found it so don't need the link).

Here are the wParam values for use with this message from winuser.h. If you don't have that file, you can google up info by searching on "WM_VSCROLL winuser.h":

0 SB_LINEUP Scrolls one line up.
1 SB_LINEDOWN Scrolls one line down.
2 SB_PAGEUP Scrolls one page up.
3 SB_PAGEDOWN Scrolls one page down.
4 SB_THUMBPOSITION The user has dragged the scroll box (thumb) and released the mouse button. The high-order word indicates the position of the scroll box at the end of the drag operation.
5 SB_THUMBTRACK The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The high-order word indicates the position that the scroll box has been dragged to.
6 SB_TOP Scrolls to the upper left.
7 SB_BOTTOM Scrolls to the lower right.
8 SB_ENDSCROLL Ends scroll.

Rajat has also posted a "Tutorial on posting messages to Windows" here:
http://www.autohotkey.com/forum/viewtopic.php?t=126


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2004, 11:02 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I researched the tray menu problem described above. One workaround is SetMouseDelay -1, perhaps only to affect your "MouseClick right" commands and not the rest of the script.

Here's the reason for the tray menu misbehavior:
When your subroutine does "MouseClick right" and the mouse cursor is on the tray icon, the mouse-down gets sent, but during the MouseDelay that occurs prior to the mouse-up, the program retrieves messages and discovers that the tray menu should be opened. It does this but its thread becomes stuck in the menu tracking loop, so the mouse-up is neither sent nor received until after the menu is dismissed. Since the mouse-up is needed for the mouse to be able to select items in the menu, the menu does not function properly (except via keyboard).

Other than SetMouseDelay -1, I do not see an easy fix for this other than to have the program not check messages during MouseDelays that are 10ms or less, which is slightly undesirable but I might do it, especially if any of you need it.

Also, one thing I forgot to mention: You could have the script go up or down by more than one line simply by doing 2 or more SendMessage's in a row. This might sometimes be preferable to using SB_PAGEUP/PAGEDOWN

Your script is so nice that maybe I should post it on the web site somewhere. The only drawback I see to it is that you can't do right-click drags (nor anything else that requires the right button to be held down)while it is in effect. I don't see an easy solution for this but maybe you will, or maybe it's just a small price to pay for the uber-mouse functionality you provided.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 21st, 2004, 9:58 pm 
Offline

Joined: April 15th, 2004, 5:33 pm
Posts: 181
Hi skrommel,
something of the topic.

I guess you're are using a monitor/LCD > 1024x768 and therefore has decided to post this with the same resolution settings.

That means for those <= 1024x768 (maybe the majority) to be forced to scroll from left to the right to be able to see the end of each line. That could be a l'ill anoying :roll:

But maybe I'm wrong ...


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 49 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