Lupin III.
Joined: 14 Jul 2005 Posts: 4
|
Posted: Thu Jul 14, 2005 6:50 pm Post subject: Quicklaunch by mouseclick |
|
|
This is the first AHK-script I have written. It took me quite a while to get used to the syntax, since I mostly program using C-like languages.
This script shows the contents of given directories in a popupmenu, if you hold down the middle mousebutton for some time. One of the directories would preferably be the quicklaunch-folder, but others can be specified to. The menuitems can also be cascaded.
| Code: |
;/* time in ms to hold the middle mouse button before the menu appears */
LUPIN_QM_holdtime = 200
;/* define directories containing commands (e.g. Quick Launch) */
LUPIN_QM_directory1 = C:\Dokumente und Einstellungen\Lupin\Anwendungsdaten\Microsoft\Internet Explorer\Quick Launch 3
LUPIN_QM_directory2 = C:\Dokumente und Einstellungen\Lupin\Anwendungsdaten\Microsoft\Internet Explorer\Quick Launch
LUPIN_QM_directory3 = %A_ScriptDir%\Media
LUPIN_QM_directory4 = %A_ScriptDir%\Networking
;/* show submenu for each directory */
LUPIN_QM_cascade := false
;/* create the menu on startup */
LUPIN_QM_createmenu()
;/* ------------------------------------------------------------------- */
~MButton::
LUPIN_QM_showmenu()
return
;/* ------------------------------------------------------------------- */
;/* ------------------------------------------------------------------- */
;/* shows the menu if mousebutton is held long enough ----------------- */
LUPIN_QM_showmenu()
{
global LUPIN_QM_holdtime
_howlong = 0
Loop
{
_howlong ++
Sleep, 10
if (_howlong >= LUPIN_QM_holdtime / 10)
{
;/* holdtime exceeded -> show menu */
Menu, LUPIN_QM_menu, Show
return
}
GetKeyState, MButton, MButton, P
;/* break, if mousebutton is released */
IfEqual, MButton, U, Break
}
}
;/* ------------------------------------------------------------------- */
;/* ------------------------------------------------------------------- */
;/* creates the mainmenu ---------------------------------------------- */
LUPIN_QM_createmenu()
{
_directory_counter = 1
Loop
{
;/* loop through all directories given */
if (LUPIN_QM_directory%_directory_counter%)
{
if (FileExist(LUPIN_QM_directory%_directory_counter%))
{
if (_directory_counter > 1)
{
;/* add a separator before each directory except the first */
Menu, LUPIN_QM_menu, Add
}
LUPIN_QM_createitems(LUPIN_QM_directory%_directory_counter%)
}
_directory_counter ++
}
else
{
;/* break, after first empty array-value */
break
}
}
}
;/* ------------------------------------------------------------------- */
;/* ------------------------------------------------------------------- */
;/* adds items for every file in the directory ------------------------ */
;/* (creates submenu if option is set) -------------------------------- */
LUPIN_QM_createitems(_directory)
{
global LUPIN_QM_cascade
if (LUPIN_QM_cascade)
{
;/* cascading -> use directory-name as submenu-label */
Loop, Parse, _directory, \
{
_last_directory = %A_LoopField%
}
_menu = %_last_directory%
}
else
{
;/* if not cascading, use default menu */
_menu = LUPIN_QM_menu
}
_files := ""
;/* read the commands */
Loop, %_directory%\*.*, 1, 0
{
_files := _files "|" A_LoopFileLongPath
}
;/* sort the commands */
Sort, _files, D|
;/* create the menu */
Loop, Parse, _files, |
{
SplitPath, A_LoopField, _fn, _dir, _ext, _fn_noext
if (_fn <> "")
{
;/* add an entry for each file found in the directory */
LUPIN_QM_setcommand(_menu, _fn_noext, A_LoopField)
Menu, %_menu%, Add, %_fn_noext%, LUPIN_QM_selected
}
}
if (LUPIN_QM_cascade)
{
;/* add the submenu for the directory to the mainmenu */
Menu, LUPIN_QM_menu, Add, %_menu%, :%_menu%
}
}
;/* ------------------------------------------------------------------- */
;/* ------------------------------------------------------------------- */
;/* stores the commands in a global array, ---------------------------- */
;/* to get them by A_ThisMenu/A_ThisMenuItem -------------------------- */
LUPIN_QM_commandcount = 0
LUPIN_QM_setcommand(_menu, _item, _command)
{
global
LUPIN_QM_commandcount ++
;/* the arrayelement contains the command separated by | from menu-menuitem */
LUPIN_QM_commands%LUPIN_QM_commandcount% = %_command%|%_menu%%_item%
}
;/* ------------------------------------------------------------------- */
;/* ------------------------------------------------------------------- */
;/* gets the command by menu-menuitem-name ---------------------------- */
LUPIN_QM_getcommand(_menu, _item)
{
global
Loop %LUPIN_QM_commandcount%
{
;/* search all strings in the commands array */
_needle = |%_menu%%_item%
_commandlength := InStr(LUPIN_QM_commands%A_Index%, _needle)
if (_commandlength > 0)
{
StringLeft, _command, LUPIN_QM_commands%A_Index%, % _commandlength - 1
return _command
}
}
return false
}
;/* ------------------------------------------------------------------- */
;/* ------------------------------------------------------------------- */
;/* execute the command associated with the selected menuitem --------- */
LUPIN_QM_selected:
_command := LUPIN_QM_getcommand(A_ThisMenu, A_ThisMenuItem)
if (_command)
{
Run, %_command%
}
return
;/* ------------------------------------------------------------------- */
|
There are still things on my wishlist:
first I would like to use the standard-icons in the menues to make it more intuitive. I also thought of using some other kind of UI (eg. radial menues would be nice), but I don't know how to implement these with AHK.
Second I still coudn't merge it with the niftywindows-script, when I still want to use the middle mousebutton as hotkey.
Got some suggestions on these points?
btw: IMHO, autohotkey needs some "real" arrays! |
|