The problem on 3 places, where I add ★★★
The problem if I uncomment this code: the oneClick is reconized like a dblClick.
Now I don’t know what to do…
(The goal of this <tf> Lib is to just include it to quick write code for testing.
One click on trayIcon reload the script.
But il’s possible to simply add menu, of other functions to trigger if clicks on trayIcon)
Code: Select all
;#Requires AutoHotkey 2.0-beta.3
#NoTrayIcon
#SingleInstance force
Persistent
/*
NameSpace:
CTrayMenu → global TrayMenu
CTrayIcon → global TrayIcon
CConsole → global Console
<ƒ_>
Hotkeys:
TrayIcon.reload →
Console.show → <#C
Usage:
OneClick → reload
DblClick → Menu.default (if def)
or
OneClick → TrayIcon_onClick
DblClick → TrayIcon_onDblClick
*/
;#Include <ƒ>
ƒ_ScriptName( ){
splitPath a_ScriptFullPath,,,, &out_NameNoExt
return out_NameNoExt
}
#Include ..\..\AutoHotkey\Lib\CConsole_f.ahk
global Console := CConsole()
Console.hotkey := "<#C"
Console.activate
<#V::Console.log "`n"
;global Console := CConsole() ; ★★★ if I use this → BUG
;class CConsole {
; log(*){
; }
; clear(){
; }
;}
global TrayMenu := CTrayMenu()
global TrayIcon := CTrayIcon()
class CTrayMenu extends Menu
{
__new(){
;; Menu
a_AllowMainWindow := false
this.Cmds := Map()
this.delete()
smnAhk := Menu()
smnAhk.addStandard()
smnAhk.default := "&Reload Script"
this.add("AutoHotkey", smnAhk)
this.add
this.setIcon "AutoHotkey", "AutoHotkey64.exe", 1, 16
;this.clickCount := 2 (default)
}
add( cmdName:=unset, cmdFunc:=unset ){
if !isSet(cmdName)
super.add
else {
super.add( cmdName, cmdFunc )
this.Cmds[ cmdName ] := cmdFunc
}
}
}
class CTrayIcon
{
__new(){
this.set "AutoHotkey64.exe", 2
this.tip := ƒ_ScriptName()
onMessage 0x404, objBindMethod(this, "AHK_NOTIFYICON")
a_IconHidden := false
this.Cmds := Map()
this.devTime := true ; ★★★ if I false this → BUG
} ;
set( fileName, iconNumber:=1, freeze:=0 ){
traySetIcon(fileName, iconNumber, freeze)
} ;
number {
get => a_IconNumber
set {
this.set( this.file, value )
}
} ;
file {
get => a_IconFile
} ;
tip {
get => a_IconTip
set => a_IconTip := value
} ;
reloadKey {
set {
try {
hotkey value, objBindMethod( this, "reload" )
} catch Error as Err {
msgBox( Err.message, this.tip )
}
}
} ;
reload(*){
reload
} ;
onClick(){
if true or this.devTime {
Console.log "➽ " a_ThisFunc
soundbeep 3000,30
}
defautName := TrayMenu.default
if isSet(TrayIcon_onClick) and TrayIcon_onClick.hasBase(Func.prototype) {
TrayIcon_onClick()
} else if defautName and TrayMenu.clickCount==1 {
funcDefault := TrayMenu.Cmds[defautName]
funcDefault()
} else {
r := msgBox("Reload?", a_IconTip, 0x1)
if r=='OK'
this.reload()
}
}
onDblClick(from:=''){
if true or this.devTime {
Console.log "➽ " a_ThisFunc " " from
soundbeep 1000,30
soundbeep 1000,30
}
defautName := TrayMenu.default
if isSet(TrayIcon_onDblClick) and TrayIcon_onDblClick.hasBase(Func.prototype) {
TrayIcon_onDblClick()
} else if defautName and TrayMenu.clickCount==2 {
funcDefault := TrayMenu.Cmds[defautName]
funcDefault()
}
}
AHK_NOTIFYICON( wParam, lParam, * ){
static this_onClick := objBindMethod(this, "onClick")
static dblClicTime := dllCall("User32.dll\GetDoubleClickTime", 'Uint')
wm_display(lParam, plus:=''){
; for dev time
if this.devTime {
static wm := Map(
0x200, "WM_MOUSE_MOVE",
0x201, "WM_L BUTTON_DOWN",
0x202, "WM_L BUTTON_UP",
0x203, "WM_L BUTTON_DBLCLK",
0x204, "WM_R_BUTTON_DOWN",
0x205, "WM_R_BUTTON_UP",
0x02A3, "WM_MOUSE_LEAVE", ; never apppend
) ;
if wm.has(lParam)
Console.log format("0x{1:04X}", lParam) " ●" wm[lParam] "● ", plus
else
Console.log format("0x{1:04X}", lParam) " ●?●", plus
}
} ;
/* if lParam==0x200 ; WM_MOUSEMOVE
wm_display(lParam)
*/
if lParam==0x201 { ; WM_LBUTTONDOWN
setTimer this_onClick, -dblClicTime
wm_display(lParam) ; ★★★ if I comment this → BUG
return 0
}
if lParam==0x202 { ; WM_LBUTTONUP
setTimer this_onClick, 0
;wm_display(lParam)
this.onDblClick("WM_LBUTTONUP")
return 0
}
if lParam==0x203 { ; WM_LBUTTONDBLCLK
setTimer this_onClick, 0
;wm_display(lParam)
; microsoft say WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK et WM_LBUTTONUP.
return 0
}
if lParam==0x204 { ; WM_RBUTTONDOWN
wm_display(lParam)
if TrayMenu.default {
if ( (TrayMenu.clickCount==2
and isSet(TrayIcon_onDblClick) and TrayIcon_onDblClick.hasBase(Func.prototype))
or (TrayMenu.clickCount==1
and isSet(TrayIcon_onClick) and TrayIcon_onClick.hasBase(Func.prototype)) )
TrayMenu.default := ''
}
return 0
}
if lParam==0x205 { ; WM_RBUTTONUP
;wm_display(lParam)
TrayMenu.show
return 1
}
}
}
Code: Select all
#Requires AutoHotkey 2.0-beta.3
#Include <tf>
/*
If Click on TrayIcon → reload
If DblClick on TrayIcon → DoNothing, but bdlClick is detected
*/
TrayMenu.add "Effacer console", clear
clear(*){
Console.clear
}
TrayMenu.add("Bip!", bip)
bip(*){
soundBeep 1500,150
Console.log "➜ TrayMenu.default =Bip! "
}
/*
If a default menu is defined (on 1 or 2 clicks)
it will be executed before defaut
*/
;TrayMenu.default := "Bip!"
;TrayMenu.clickCount := 1
/*
If you define TrayIcon_onClick() or TrayIcon_onDblClick()
it will be executed before anything else
*/
;TrayIcon_onClick(){
; Console.log "➜ " a_ThisFunc
;}
;TrayIcon_onDblClick(){
; Console.log "➜ " a_ThisFunc
;}
Code: Select all
;#Requires AutoHotkey 2.0-beta.3
class CConsole {
__new( title := "Console" ) {
HWND := winExist( title " ahk_class Notepad" )
if ( HWND ) {
PID := WinGetPID( "ahk_id " HWND )
this.ahkPID := "ahk_pid " PID
this.ahkHWND := "ahk_id " HWND
this.clear
} else {
detectHiddenWindows 1
try run( "notepad.exe",,"Hide", &PID )
this.ahkPID := "ahk_pid " PID
HWND := winWait(this.ahkPID)
if HWND==0
return
this.ahkHWND := "ahk_id " HWND
winMove(0, 0, a_ScreenWidth/4, a_ScreenHeight, this.ahkHWND)
winSetTitle( title, this.ahkHWND )
winShow( this.ahkHWND )
}
}
hotkey {
set {
try {
hotkey value, objBindMethod( this, "show" )
} catch Error as Err {
a := 2
msgBox( Err.message, "AHK Console" )
}
}
}
log( variables* ) {
if ( !winExist( this.ahkHWND ) )
return
ControlSend( "{Ctrl down}{End}", "Edit1", this.ahkHWND )
lastIndex := variables.length
if lastIndex == 0
EditPaste( "`r`n", "Edit1", this.ahkHWND )
for index, var in variables {
if (isObject(var)) {
EditPaste( "{`r`n", "Edit1", this.ahkHWND )
for key, value in var {
EditPaste( " " key ": " value "`r`n", "Edit1", this.ahkHWND )
}
EditPaste( "}`r`n", "Edit1", this.ahkHWND )
} else {
sep := (index==lastIndex? "`r`n" : " ")
EditPaste( var sep, "Edit1", this.ahkHWND )
}
}
}
show( v* ) {
if ( !winExist( this.ahkHWND ) ) {
msgBox( "La Console est fermée." )
return
}
winSetAlwaysOnTop( true, this.ahkHWND )
winSetAlwaysOnTop( false, this.ahkHWND )
}
activate() {
WinActivate( this.ahkHWND )
;
}
clear() {
ControlSetText( "", "Edit1", this.ahkHWND )
;
}
test() {
this.log( "Notice that `r`n is a Carriage Return." )
this.log( "New line", "…plus." )
}
}