SlimShady Posted May 13, 2004 Posted May 13, 2004 I made a script that manages your most used commands/applications using hotkeys.For example Windows key+N for notepad.Instructions:- Run the script (there will only be an AutoIt icon in the system tray)If you created hotkeys earlier, they will be set now.- Press CTRL+ALT+C to configure the hotkeys(the commands will be shown)- If you add a hotkey, you will be asked whether (? is it spelled right ?) you want to choose a program or enter a command so it will run when the hotkey is pressed.- Press CTRL+ALT+X to exit the scriptThe hotkey will be set when you finished creating a hotkey or edit.And unset when you delete one.Features:Add hotkeysEdit hotkeysDelete hotkeysShow all hotkeysI haven't made it 'newbie-proof' yet, but I'm working on it.If you have any suggestions, requests or problems, please post it here.Here it is:expandcollapse popupAutoItSetOption("RunErrorsFatal", 0) Global $Count, $IniFile $IniFile = @ScriptDir & "\hotkeys.ini" HotKeySet("^!c", "ConfigHotkeys") ;---- Config Hotkeys HotKeySet("^!x", "ExitNow") ;---- Exit HotkeyManager $Count = IniRead($IniFile, "Settings", "Count", "0") $Count = Number($Count) SetHotkeys($Count) SleepNow() Func SleepNow() Sleep(24 * 60 * 60 * 1000) EndFunc Func ConfigHotkeys() $Count = IniRead($IniFile, "Settings", "Count", "0") $Count = Number($Count) If $Count = 0 Then Do MsgBox(0 + 48, "Hotkey Manager", "No hotkeys have been set!") AddHotkey($Count) $Count = IniRead($IniFile, "Settings", "Count", "0") $Count = Number($Count) Until $Count <> 0 EndIf $Input = "hotkeys using the following commands:" & @CRLF $Input = $Input & " edit, add, delete, show" $Input = $Input & @CRLF & @CRLF & "If you add a hotkey," $Input = $Input & " it will automatically be set afterwards." $Input = $Input & @CRLF & "And if you edit/delete one," $Input = $Input & " the hotkey will be unset." $Command = InputBox("Hotkey Manager", "You can configure " & $Input, "", "", 350, 250) Select Case $Command = "add" AddHotkey($Count) Case $Command = "delete" DelHotkey($Count) Case $Command = "edit" EditHotkey($Count) Case $Command = "show" $Part = "# = Win" $Part = $Part & @CRLF & "^ = Ctrl" $Part = $Part & @CRLF & "! = Alt" $Part = $Part & @CRLF & "+ = Shift" MsgBox(0, "Hotkey Manager", $Part & @CRLF & @CRLF & List()) EndSelect $Count = IniRead($IniFile, "Settings", "Count", "0") $Count = Number($Count) SetHotkeys($Count) EndFunc Func ExitNow() Exit EndFunc Func AddHotkey($Count) $Number = $Count + 1 $Part = "Enter the hotkey you want to set. Key modifiers:" $Part = $Part & @CRLF & "# = Win" $Part = $Part & @CRLF & "^ = Ctrl" $Part = $Part & @CRLF & "! = Alt" $Part = $Part & @CRLF & "+ = Shift" $Add = InputBox("1/3) Add Hotkey #" & $Number, $Part, "", "", 350, 250) If $Add = "" Then SleepNow() $Ask = MsgBox(3 + 32, "2/3 Add Hotkey #" & $Number, "Would you like to run a program or enter a command?" & _ @CRLF & "[Yes] for program, [No] for command") If $Ask = 6 Then $Program = FileOpenDialog("3/3) Choose a file to run", "", "All (*.*)", 1) ElseIf $Ask = 7 Then $Program = InputBox("3/3) Add Hotkey#" & $Number, "Enter a command to run for:" & @CRLF & Chr(34) & $Add & Chr(34), "", "", 350, 250) Else SleepNow() EndIf If $Add <> "" AND $Program <> "" Then IniWrite($IniFile, "Hotkeys", "Hotkey" & $Number, $Add) IniWrite($IniFile, "Run", "Hotkey" & $Number, $Program) IniWrite($IniFile, "Settings", "Count", $Number) EndIf EndFunc Func EditHotkey($Count) $EditNum = InputBox("1/3) Edit hotkeys", "Which hotkey would you like to edit?" & @CRLF & @CRLF & List(), "", "", 350, 250) If $EditNum = "" Then SleepNow() $Part1 = "Enter the hotkey you want to set. Key modifiers:" $Part2 = @CRLF & "# = Win" $Part3 = @CRLF & "^ = Ctrl" $Part4 = @CRLF & "! = Alt" $Part5 = @CRLF & "+ = Shift" $DelHotkey = IniRead($IniFile, "Hotkeys", "Hotkey" & $EditNum, "") HotKeySet($DelHotkey) $Hotkey = IniRead($IniFile, "Hotkeys", "Hotkey" & $EditNum, "0") $Edit = InputBox("2/3) Edit Hotkey #" & $EditNum, $Part1 & $Part2 & $Part3 & $Part4 & $Part5, $Hotkey, "", 350, 250) If $Edit <> "" Then IniWrite($IniFile, "Hotkeys", "Hotkey" & $EditNum, $Edit) Else SleepNow() EndIf $Ask = MsgBox(3 + 32, "2/3 Edit Hotkey #" & $EditNum, "Would you like to run a program or enter a command?" _ & @CRLF & "[Yes] for program, [No] for command") If $Ask = 6 Then $Program = FileOpenDialog("3/3) Choose a file to run", "", "All (*.*)", 1) ElseIf $Ask = 7 Then $Program = IniRead($IniFile, "Run", "Hotkey" & $EditNum, "") $Program = InputBox("3/3) Edit Hotkey#" & $EditNum, "Enter a command to run for:" & @CRLF & Chr(34) & $Edit & Chr(34), $Program, "", 350, 250) Else $Program = "" SetHotkeys($Count) SleepNow() EndIf If $Program <> "" AND $Edit <> "" Then IniWrite($IniFile, "Run", "Hotkey" & $EditNum, $Program) IniWrite($IniFile, "Hotkeys", "Hotkey" & $EditNum, $Edit) EndIf EndFunc Func SetHotkeys($Count) If $Count = 0 Then Do MsgBox(0 + 48, "Hotkey Manager", "No hotkeys have been set!") AddHotkey($Count) $Count = IniRead($IniFile, "Settings", "Count", "0") $Count = Number($Count) Until $Count <> 0 EndIf $Number = $Count + 1 For $i = 1 To $Number $hotkey = IniRead($IniFile, "Hotkeys", "Hotkey" & $i, "") HotKeySet($hotkey, "DoFunction" & $i) Next EndFunc Func List() $Count = IniRead($IniFile, "Settings", "Count", "0") $Count = Number($Count) For $i = 1 To $Count $Program = IniRead($IniFile, "Run", "Hotkey" & $i, "") $hotkey = IniRead($IniFile, "Hotkeys", "Hotkey" & $i, "") $list = $list & $i & ") " & $hotkey & @TAB & $Program & @CRLF Next Return $list EndFunc Func DelHotkey($Count) $Number = InputBox("Hotkey Manager", "Delete which hotkey?" & @CRLF & @CRLF & List(), "", "", 350, 250) If $Number = "" Then SleepNow() $DelHotkey = IniRead($IniFile, "Hotkeys", "Hotkey" & $Number, "") HotKeySet($DelHotkey) IniDelete($IniFile, "Hotkeys", "Hotkey" & $Number) IniDelete($IniFile, "Run", "Hotkey" & $Number) If $Count > $Number Then $Num = $Number + 1 For $i = $Number To $Count - 1 ;---------- Run $Repair = IniRead($IniFile, "Run", "Hotkey" & $Num, "") IniDelete($IniFile, "Run", "Hotkey" & $Num) IniWrite($IniFile, "Run", "Hotkey" & $Number, $Repair) ;---------- Hotkey $Repair = IniRead($IniFile, "Hotkeys", "Hotkey" & $Num, "") IniDelete($IniFile, "Hotkeys", "Hotkey" & $Num) IniWrite($IniFile, "Hotkeys", "Hotkey" & $Number, $Repair) $Number = $Number + 1 $Num = $Number + 1 Next EndIf $Count = $Count - 1 IniWrite($IniFile, "Settings", "Count", $Count) EndFunc Func DoFunction1() $Program = IniRead($IniFile, "Run", "Hotkey1", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction2() $Program = IniRead($IniFile, "Run", "Hotkey2", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction3() $Program = IniRead($IniFile, "Run", "Hotkey3", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction4() $Program = IniRead($IniFile, "Run", "Hotkey4", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction5() $Program = IniRead($IniFile, "Run", "Hotkey5", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction6() $Program = IniRead($IniFile, "Run", "Hotkey6", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction7() $Program = IniRead($IniFile, "Run", "Hotkey7", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction8() $Program = IniRead($IniFile, "Run", "Hotkey8", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction9() $Program = IniRead($IniFile, "Run", "Hotkey9", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction10() $Program = IniRead($IniFile, "Run", "Hotkey10", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction11() $Program = IniRead($IniFile, "Run", "Hotkey11", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction12() $Program = IniRead($IniFile, "Run", "Hotkey12", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction13() $Program = IniRead($IniFile, "Run", "Hotkey13", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction14() $Program = IniRead($IniFile, "Run", "Hotkey14", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc Func DoFunction15() $Program = IniRead($IniFile, "Run", "Hotkey15", "") Run(@ComSpec & " /c Start " & FileGetShortName($Program), "", @SW_HIDE) EndFunc
Valik Posted May 13, 2004 Posted May 13, 2004 Here's one thing you need to be aware of. If a second AutoIt script is launched and it uses a key-combination configured in this hotkey manager, the second script will take over the hotkey and it will no longer work without restarting the hotkey manager (Or at least re-calling HotKeySet()).
SlimShady Posted May 13, 2004 Author Posted May 13, 2004 But that's the user's responsibility. If someone uses a script that's controlled by hotkeys, that someone would know or (at least notice) that 'something' wouldn't/doesn't work.
SlimShady Posted May 13, 2004 Author Posted May 13, 2004 Thanks. I now notice that my scripts are usual very long .
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now