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 

Right Click on the desktop

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
antonyb



Joined: 26 May 2004
Posts: 61

PostPosted: Wed May 26, 2004 12:29 pm    Post subject: Right Click on the desktop Reply with quote

Hi,

Just wondered if anyone knew a way of writing a script that allows me to remap the Right Click of my mouse to run an application, but only when the mouse is over the desktop? When the mouse is over an application window I'd like the normal application-specfic right click menu to show.

Is that possible?

thanks,

tony.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Wed May 26, 2004 1:45 pm    Post subject: Reply with quote

There is a section in the FAQ ( http://www.autohotkey.com/docs/FAQ.htm ) that deals with this, but it doesn't specifically address the mouse or the desktop. So here is an example that I think does what you want (it won't work on Windows 9x):
Code:
~RButton::
WinGetTitle, active_title, A
if active_title <> Program Manager
   if active_title <>  ; Sometimes the desktop shows a blank title, at least on my system.
      return
; This is a double-confirmation that desktop is active.  Might not be necessary:
WinGetText, active_text, A
IfNotInString, active_text, FolderView
   if active_text <>
      return
MsgBox, You right-clicked the desktop.
return

I had a little trouble getting it to consistently recognize the desktop on my XP system, which is why the detection is more complex than just checking for Program Manager.

Also, the context menu will probably appear when you right click to the desktop. To prevent that, a loop can be added that waits for the mouse button to be released, at which time "Send {Escape}" is executed to dismiss the menu.
Back to top
View user's profile Send private message Send e-mail
antonyb



Joined: 26 May 2004
Posts: 61

PostPosted: Wed May 26, 2004 2:28 pm    Post subject: Reply with quote

Ooh - very cool - thanks!

I added:
Code:
Loop
{
  Sleep, 5
  GetKeyState, RButton, RButton, P
  IfEqual, RButton, U, Break
}

Send {Escape}


before the MsgBox line, and it now works, though the default desktop right click menu does flash up before disappearing. No way around this, right?

Thanks!

tony.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Wed May 26, 2004 3:13 pm    Post subject: Reply with quote

Quote:
though the default desktop right click menu does flash up before disappearing. No way around this, right?

Here's a possibility, but it appears to have a problem with the desktop not being active sometimes. I think this is because the right-click is suppressed (hidden from the system), so the desktop doesn't always become active:
Code:
RButton::
WinGetTitle, active_title, A
if active_title <> Program Manager
   if active_title <>  ; Sometimes the desktop shows a blank title, at least on my system.
   {
      MouseClick, right, , , , , D
      Loop
      {
         Sleep, 10
         GetKeyState, RButtonState, RButton, P
         if RButtonState = U  ; button has been released
            break
      }
      MouseClick, right, , , , , U
      return
   }
MsgBox, You right-clicked the desktop.
return


What might fix the above is a new feature that detects the window that's currently under the mouse cursor. There's an item on the to-do list to add this.
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Thu Jul 29, 2004 1:11 pm    Post subject: Reply with quote

There is a related topic with a more advanced script at http://www.autohotkey.com/forum/viewtopic.php?p=2716#2716
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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