Sign in to follow this  
Followers 0
gigi1

Hotkey and Version Helper for Scite

1 post in this topic

Hi, this is my first post in example scripts!

i made this little program for two reasons: (1) i don't like the position of the char $ in the italian keyboard (i don't know about other layouts) (2)i lost my job some times due to AutoIt saving before executing.

What it does:

- Writes $ when the user press ò (this is useful for italian layout, but can be changed)

- When the user press F5 the program saves the script in another file, with an increased version number (ex: myscript v3.au3 -> myscript v4.au3; myanotherscript v0.2.3.au3 -> myanotherscript v0.2.4.au3) and then execute the script

[note that i added a dialog box to verify the saving name, it is just for safety for now since i haven't tested much, can be removed by commenting out lines 61 and 67]

- When the user press F6 the program saves the script and execute it (normal behavior)

know bugs:

- does not handles simple script names properly (ex: myscript.au3 -> myscript.au3v1.au3)

sincerely i don't mind this one, just add a v1 or v0.1 before startin a new project

Note: you can always pause the script from the tray menu, or save/save as manually

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

If FileExists(@ScriptDir&"\HotKeyConfig.ini") Then      ;initialize hotkeys
    $HotKey = IniRead(@ScriptDir&"\HotkeyConfig.ini", "HotKeySetup", "HotKey", "ò")
    $SendKey = IniRead(@ScriptDir&"\HotkeyConfig.ini", "HotKeySetup", "SendKey", "{:content:}quot;)
Else
    $HotKey = "ò"
    $SendKey = "{:content:}quot;
EndIf

Opt("TrayMenuMode",1)       ;initialize tray menu
Opt("WinTitleMatchMode", 2)

$ExitButton = TrayCreateItem("Exit")
$PauseButton = TrayCreateItem("Pause")
TrayCreateItem("")
$ConfigButton = TrayCreateItem("Configure HotKeys")
$Pause = True
TogglePause()

While 1
    $msg = TrayGetMsg()
    Switch $msg
        Case 0
            ContinueLoop
        Case $msg = $ExitButton
            Exit
        Case $PauseButton
            TogglePause()
        Case $ConfigButton
            ConfigInitialize()
    EndSwitch
WEnd

Func HotKey()
    Send($SendKey)
EndFunc

Func SaveAsAndExecute()
    TogglePause()
    Send("^+s")
    Local $ClipOld = ClipGet()
    WinWaitActive("Save File")
    Sleep(50)
    Send("^x")
    Sleep(50)
    Local $FullName = ClipGet()
    Local $Name = StringMid($FullName, 1, StringInStr($FullName, "v", 1, -1)-1)     ;retrieves the file name (without version info)
    Local $Version = StringMid($FullName, StringInStr($FullName, "v", 1, -1))       ;retrieves the version (complete with v.[version].au3
    Local $VersionNo = StringMid($Version, 2, StringLen($Version)-5)                ;retrieves the plain version number
    If StringInStr($VersionNo, ".") = 0 Then                                        ;check if version has points (ex: 0.1.3) or not (ex: 3)
        $VersionNo = Execute($VersionNo+1)
    Else
        Local $LastNo = StringMid($VersionNo, StringInStr($VersionNo, ".", 0, -1)+1)
        Local $FirstNo = StringMid($VersionNo, 1, StringInStr($VersionNo, ".", 0, -1))
        $LastNo = Execute($LastNo+1)
        $VersionNo = $FirstNo&$LastNo
    EndIf
    $FullName = $Name&"v"&$VersionNo&".au3"
    If MsgBox(1, "Versionhelper", "Saving under "&$FullName&", continue?")=1 Then
        ClipPut($FullName)
        Send("^v")
        Send("{ENTER}")
        WinWaitActive($FullName)
        Send("{F5}")
    EndIf
    TogglePause()
EndFunc

Func SaveAndExecute()
    TogglePause()
    Send("^s")
    Sleep(50)
    Send("{F5}")
    TogglePause()
EndFunc

Func TogglePause()
    $Pause = Not $Pause
    If $Pause Then
        HotKeySet($HotKey)
        HotKeySet("{F5}")
        HotKeySet("{F6}")
    Else
        HotKeySet($HotKey, "HotKey")
        HotKeySet("{F5}", "SaveAsAndExecute")
        HotKeySet("{F6}", "SaveAndExecute")
    EndIf
EndFunc

Func ConfigInitialize()
    TrayItemSetState($ConfigButton, 4)
    If FileExists(@ScriptDir&"\HotKeyConfig.ini") = 0 Then
        If MsgBox(4, "HotKeyConfig", "This procedure will create a configuration Ini file in the script directory, continue?") = 6 Then
            IniWrite(@ScriptDir&"\HotkeyConfig.ini", "HotKeySetup", "HotKey", $HotKey)
            IniWrite(@ScriptDir&"\HotkeyConfig.ini", "HotKeySetup", "SendKey", $SendKey)
            HotKeySetup()
        EndIf
    Else
        HotkeySetup()
    EndIf
EndFunc

Func HotKeySetup()
TogglePause()
$MainGui = GUICreate("Hotkeyset", 180, 98, 510, 374)
$Label1 = GUICtrlCreateLabel("Hotkey:", 8, 8, 41, 17)
$Label2 = GUICtrlCreateLabel("Key to press:", 104, 8, 65, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$HotKeyInput = GUICtrlCreateInput($HotKey, 8, 32, 57, 21)
$SendKeyInput = GUICtrlCreateInput($SendKey, 104, 32, 57, 21)
$CancelButton = GUICtrlCreateButton("Cancel", 8, 64, 65, 25, $WS_GROUP)
$OKButton = GUICtrlCreateButton("OK", 104, 64, 65, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($MainGui)
            TogglePause()
            ExitLoop
        Case $CancelButton
            GUIDelete($MainGui)
            TogglePause()
            ExitLoop
        Case $OKButton
            $HotKey = GUICtrlRead($HotKeyInput)
            $SendKey = GUICtrlRead($SendKeyInput)
            IniWrite(@ScriptDir&"\HotkeyConfig.ini", "HotKeySetup", "HotKey", $HotKey)
            IniWrite(@ScriptDir&"\HotkeyConfig.ini", "HotKeySetup", "SendKey", $SendKey)
            GUIDelete($MainGui)
            TogglePause()
            ExitLoop
    EndSwitch
    WEnd
EndFunc

i apologize if this has been already released, but i couldn't find something similar, and it is really useful for me.

Share this post


Link to post
Share on other sites



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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0