AutoHotkey Community

It is currently May 27th, 2012, 8:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: March 4th, 2006, 1:51 am 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Features:
Middle click sends a normal middle click unless:
- Over the taskbar: Closes the window whose button is under the mouse (aborts if window prompts to save,etc).
- Over the titlebar of a window: closes the window (can be made more sensitive to specific window areas - see Shimanov's post:
http://www.autohotkey.com/forum/viewtopic.php?t=8486 ).
- Over an internet explorer class window: Opens a link in a new window (keep holding the button down to switch back to the original window).

Code:

MButton::
  SetBatchLines, -1
  CoordMode, Mouse, Screen
  SetMouseDelay, -1 ; no pause after mouse clicks
  SetKeyDelay, -1 ; no pause after keys sent
  MouseGetPos, ClickX, ClickY, WindowUnderMouseID
  WinActivate, ahk_id %WindowUnderMouseID%

  ; WM_NCHITTEST
  SendMessage, 0x84,, ( ClickY << 16 )|ClickX,, ahk_id %WindowUnderMouseID%
  WM_NCHITTEST_Result =%ErrorLevel%
      /*
      #define HTERROR             (-2)
      #define HTTRANSPARENT       (-1)
      #define HTNOWHERE           0
      #define HTCLIENT            1
      #define HTCAPTION           2
      #define HTSYSMENU           3
      #define HTGROWBOX           4
      #define HTSIZE              HTGROWBOX
      #define HTMENU              5
      #define HTHSCROLL           6
      #define HTVSCROLL           7
      #define HTMINBUTTON         8
      #define HTMAXBUTTON         9
      #define HTLEFT              10
      #define HTRIGHT             11
      #define HTTOP               12
      #define HTTOPLEFT           13
      #define HTTOPRIGHT          14
      #define HTBOTTOM            15
      #define HTBOTTOMLEFT        16
      #define HTBOTTOMRIGHT       17
      #define HTBORDER            18
      #define HTREDUCE            HTMINBUTTON
      #define HTZOOM              HTMAXBUTTON
      #define HTSIZEFIRST         HTLEFT
      #define HTSIZELAST          HTBOTTOMRIGHT
      #if(WINVER >= 0x0400)
      #define HTOBJECT            19
      #define HTCLOSE             20
      #define HTHELP              21
      */



; Close window with titlebar click
  If WM_NCHITTEST_Result in 2,3,8,9,20,21 ; in titlebar enclosed area - top of window
    {
    PostMessage, 0x112, 0xF060,,, ahk_id %WindowUnderMouseID% ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE
    Return
    }



; Close taskbar program click
  IfWinActive, ahk_class Shell_TrayWnd
    {
    MouseClick, Right, %ClickX%, %ClickY%
    Sleep, 50
    Send, c
    WinWaitNotActive,  ahk_class Shell_TrayWnd,, 0.5 ; wait for save dialog, etc
    If ErrorLevel =1
      Send, !{Tab}
    Return
    }


; Open IE link in new window
  IfWinActive, ahk_class IEFrame ; going to click on a link to open in new window
    {
    If A_Cursor =Unknown ; pointer is probably the Hand icon (for links)
      {
      StatusBarGetText, IEStatusBarText, 1
      StringLeft, IEStatusBarText, IEStatusBarText, 4
      If IEStatusBarText = java ; javascript - should open in its own new window anyhow
        {
        Click, %ClickX%, %ClickY%
        SetTimer, OpenIELinkInNewWindowSleep, 400 ; new thread
        }
      Else
        {
        Send +{Click %ClickX%, %ClickY%}  ; Shift+LeftClick
        SetTimer, OpenIELinkInNewWindowSleep, 400 ; new thread
        }
      Return
      }
    }


; else send normal middle click
  If GetKeyState("MButton", "P") ; The middle button is physically down
    MouseClick, Middle, %ClickX%, %ClickY%,, Down
  Else
    MouseClick, Middle, %ClickX%, %ClickY%
Return



OpenIELinkInNewWindowSleep: ; if still holding middle mouse down, returns to original window
  SetTimer, OpenIELinkInNewWindowSleep, Off
  WinWaitNotActive, ahk_id %WindowUnderMouseID%,, 1
  Sleep, 100
  WinMaximize, A
  If GetKeyState("MButton", "P") ; The middle button is physically down
    WinActivate ahk_id %WindowUnderMouseID%
Return


Last edited by evl on May 9th, 2006, 11:32 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2006, 3:05 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Making the middle button context sensitive is very useful. I've put a lot of functions onto mine too.

Your script is ultra-context sensitive since it detects titlebar and taskbar too. Thanks for sharing it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2006, 8:55 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
I've always wanted to add some extra functionality to the middle mouse button. Thanks for the code!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2006, 7:59 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
I've made some changes to the script which make use of shimanov's code for the titlebar sensitivity to clicks:
http://www.autohotkey.com/forum/viewtopic.php?t=8486
and generally improved some of the functionality and code so posted an update above.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2006, 4:22 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
I'm a fan of this code. I've been using a variation of it since you first posted it. It's a bunch of features all bundled into the middle mouse button. Thanks for sharing! :)

I have a few questions/comments:

1) I noticed that you mix the use of MouseClick and Click. It certainly doesn't make any difference but you probably don't need to use both (?) and when using/sending Click you don't need to specify the X,Y coords since you're not repositioning the mouse.

2) There is no reason to send an Alt-Tab to return to the previous window since you already have the ID for the previous window. I would just reactiavte the window:
Code:
WinActivate ahk_id %WindowUnderMouseID%

I know. It does the exact same thing.

3) I'm not sure that you need the Sleep statements in the OpenIELinkInNewWindowSleep subroutine/timer since you are already sleeping via the WinWaitNotActive command. However, I did notice that the WinTile parameter for WinWaitNotActive is not defined correctly. Try the following:

Code:
WinWaitNotActive, ahk_id %WindowUnderMouseID%,, 1


These are all very tiny changes and I might be wrong about all of them. Once again, thanks for the code.

Them be my thoughts...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2006, 11:24 am 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
@ jballi:
Thanks for the comments:

1) I couldn't get Click to work with sending the middle mouse button down, so I reverted to just using MouseClick for that bit as it worked without any hassle. I was trying " Click Down Middle %ClickX%, %ClickY%" - but that seems to keep the middle mouse button pressed down even after you release it and it screws up the other mouse buttons until you close the script (ctrl-alt-del) and click the middle mouse again. I also tried adding "$" infront of the MButton hotkey. Maybe a bug or a mistake in my syntax?
I decided to put in the co-ords just to make sure the correct thing would be clicked if the user happened to have the mouse on the edge of a link, etc and was moving the mouse quickly. It shouldn't be necessary in 99% of clicks, but better safe than sorry.

2) You're right about Alt-Tab of course :roll: :lol:

3) The Sleep is for 2 reasons. a) The total should come to around 500ms so that the middle button state can be checked to see if the user wants to switch back to the original window or not (although I think I see your point of using SetTimer as the delay instead of the initial Sleep) otherwise the button state is checked too quickly to detect if the user really wants to hold the middle button down or was just pressign it still. b) IE can be a bit stupid sometimes and the window can steal focus if you try to switch away from it too soon, so the extra 100 ms sleep should work around that and making sure that the correct window has focus (for a split second no window has focus until the IE window is properly created I think). Also well done for catching my syntax error :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2006, 8:18 pm 
So for a person with limited progamming knowledge (but I know my way around windows fairly well) what to I do with above code? Is it ment to be compiled into a free running program or stuck in some windows system file?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2007, 3:38 am 
This is great, but it interferes with Firefox. When I middle-click on a bookmark in the menu, it does not open.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2007, 8:23 am 
I'm seeing the same behavior as vzx on a different script that uses the middle-click as a hotkey. Any ideas how to use the middle-click as a prefix key, but still retain the original functionality when clicked?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 11:59 am 
Offline

Joined: June 16th, 2007, 6:43 pm
Posts: 35
kingzulu wrote:
So for a person with limited progamming knowledge (but I know my way around windows fairly well) what to I do with above code? Is it ment to be compiled into a free running program or stuck in some windows system file?


Download autohotkey from http://www.autohotkey.com/download/Auto ... nstall.exe
Install it.
Copy the code above, paste it in notepad, save it with any name ending with .ahk
Double click the .ahk file you just made and it will launch the program.
You can make it into a .exe by right clicking the .ahk file and compiling it.

EDIT: Oops... Just saw the post date. Seems like I got late in replying. :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 8:29 am 
Offline

Joined: September 28th, 2005, 10:37 am
Posts: 3
Location: India
Thank you. Was looking for something like this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 7:57 pm 
The taskbar middle click function does not work on vista. I tried fooling around with the code myself with no luck. Any ideas on how to make it work?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 7:57 pm 
The taskbar middle click function does not work on vista. I tried fooling around with the code myself with no luck. Any ideas on how to make it work?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2008, 2:21 am 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
The section you need to look at is "; Close taskbar program click" - it doesn't do anything fancy though, just send a right click and press c to close, so perhaps the shortcut is different in Vista, or, the menu is taking too long to display so increase the sleep time: e.g. "Sleep, 100"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 4:27 am 
Offline

Joined: June 18th, 2008, 8:33 pm
Posts: 20
Someguy! wrote:
The taskbar middle click function does not work on vista. I tried fooling around with the code myself with no luck. Any ideas on how to make it work?


I messed around with it for about five minutes and found that if I move the section commented "Close window with titlebar click" under the section titled "Close taskbar program click" it works. I am not sure why, but I really don't mind.

_________________
ttrickyy


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: tomoe_uehara, xXDarknessXx, Yahoo [Bot] and 9 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