 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
antonyb
Joined: 26 May 2004 Posts: 61
|
Posted: Wed May 26, 2004 12:29 pm Post subject: Right Click on the desktop |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Wed May 26, 2004 1:45 pm Post subject: |
|
|
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 |
|
 |
antonyb
Joined: 26 May 2004 Posts: 61
|
Posted: Wed May 26, 2004 2:28 pm Post subject: |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Wed May 26, 2004 3:13 pm Post subject: |
|
|
| 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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|