AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Advanced mouse functions

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
skrommel (as guest)
Guest





PostPosted: Tue Apr 20, 2004 1:31 am    Post subject: Advanced mouse functions Reply with quote

Very Happy 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
Back to top
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Tue Apr 20, 2004 2:04 am    Post subject: Reply with quote

i'd problem with rt-clicking the tray icon of script & selecting exit...and strangely only with this script's icon Exclamation
_________________
Back to top
View user's profile Send private message
skrommel
Guest





PostPosted: Tue Apr 20, 2004 2:14 am    Post subject: Me too Reply with quote

Sad I too have this problem exactly. Maybe cmallet knows?

Skrommel
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Tue Apr 20, 2004 2:55 am    Post subject: Reply with quote

Jeez, that script is amazing. Such imagination Smile

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.
Back to top
View user's profile Send private message Send e-mail
skrommel
Guest





PostPosted: Tue Apr 20, 2004 3:06 am    Post subject: Better Reply with quote

But still better than Send,{PgUp}... Smile
Isn't there a Window message SB_PAGEDOWN something, too? Hmmm.... Maybe another function, cmallet? Scroll,line|page|percentage,direction,amount,window,windowtext

Skrommel
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Tue Apr 20, 2004 12:39 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
skrommel
Guest





PostPosted: Tue Apr 20, 2004 7:32 pm    Post subject: Not for us simple minded Reply with quote

Smile 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
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Tue Apr 20, 2004 7:40 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Tue Apr 20, 2004 11:02 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Beastmaster



Joined: 15 Apr 2004
Posts: 182

PostPosted: Wed Apr 21, 2004 9:58 pm    Post subject: Reply with quote

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 Rolling Eyes

But maybe I'm wrong ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group