Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Single- and double-click of scripts Tray icon


  • Please log in to reply
6 replies to this topic
Landvermesser
  • Members
  • 51 posts
  • Last active: Aug 12 2008 09:02 AM
  • Joined: 03 Nov 2004
The script illustrates a method of recognition of single- and double-click an icon in system tray.

The basic difficulty - definition of a source of users select (an icon or the menu). The first variant: with definition of event " the right key of the mouse has been pressed, so the menu has been shown "

#Persistent

	Hotkey, RButton, RightClick

	Menu, Tray, Click, 1
	Menu, Tray, NoStandard
	Menu, Tray, Add, Single Click, 	SingleClick
	Menu, Tray, Add, Double Click, DoubleClick
	Menu, Tray, Default, Double Click
	Menu, Tray, Add, Exit
	Return

DoubleClick:
	If RClicked <> Yes
		{
			If Clicks =
				{
					SetTimer, SingleClick, 500
					Clicks = 1
					Return
				}
		}
	SetTimer, SingleClick, Off
	MsgBox, 0, Message, Double Click Detected!
	Clicks =
	RClicked =
	Return

SingleClick:	
	SetTimer, SingleClick, Off
	MsgBox, 0, Message, Single Click Detected!
	Clicks =
	RClicked =
	Return
	
RightClick:
	RClicked = Yes
	GetKeyState, state, RButton, P
	If state = D
		{
			Send, {RButton down}
			KeyWait, RButton
			Send, {RButton up}
		}
	Else
		{
			Send, {RButton}
		}
	RClicked =
	Return
	
Exit:
	ExitApp

The second variant: with definition of event " after the first click the mouse is not above a system tray, so the menu has been shown and the item of the menu was selected"

#Persistent

	Menu, Tray, Click, 1
	Menu, Tray, NoStandard
	Menu, Tray, Add, Single Click, 	SingleClick
	Menu, Tray, Add, Double Click, DoubleClick
	Menu, Tray, Default, Double Click
	Menu, Tray, Add, Exit
	Return

DoubleClick:
	MouseGetPos, , , WhichWindow, WhichControl
	WinGetClass, WhichClass, ahk_id %WhichWindow%
	If WhichClass = Shell_TrayWnd
		{
			IfInString, WhichControl, ToolbarWindow32
				{
					If Clicks =
						{
							SetTimer, SingleClick, 500
							Clicks = 1
							Return
						}
				}
		}
	SetTimer, SingleClick, Off
	Sleep, 500	
	MsgBox, 0, Message, Double Click Detected!
	Clicks =
	Return

SingleClick:	
	SetTimer, SingleClick, Off
	MsgBox, 0, Message, Single Click Detected!
	Clicks =
	Return
	
Exit:
	ExitApp

It is necessary only to exclude threefold- and multiply-clicks (sorry, but I donĀ“t know). Any ideas?

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
Yes!

Skrommel

user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
didnt get what this script does, can you tell me please

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:) It executes one action when you singleclick, and another action when you doubleclick the tray icon. Very handy.

user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
yes, it sounds very handy indeed

but I dont think ahk can distinguish different tray icons

this script does? can I select different tray icons and set single click and double click (right, left, middle click) actions?

how can I do this?

thanks

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:) No, only your own tray icon.

fre3zzy
  • Members
  • 6 posts
  • Last active: Feb 14 2015 06:45 AM
  • Joined: 22 Jan 2015

I'm figuring out a way to toggle Pause and Suspend my script when double clicking the tray icon. This script works perfectly well for that. Thx