Jump to content
Dan_555

Changeable Hotkey with GUI

Recommended Posts

Posted (edited)

Hi, 

here is a configurable HotKey Gui script, which i wrote for my current Project:

#include <Array.au3>
#include <ComboConstants.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <Array.au3>


Global $snip_inifile = @ScriptDir & "\" & "hotkeygui.ini"
;If $HKSTRING is changed, make sure to adjust the $z number in the SetHotkeyKeys function.
Local $HKSTRING = "[;][#;Win][!;Alt][+;Shift][^;Ctrl][0;0][1;1][2;2][3;3][4;4][5;5][6;6][7;7][8;8][9;9][a;a][b;b][c;c][d;d][e;e][f;f][g;g][h;h][i;i][j;j][k;k][l;l][m;m][n;n][o;o][p;p][q;q][r;r][s;s][t;t][u;u][v;v][w;w][x;x][y;y][z;z][{PAUSE};Pause][{BREAK};Break][{HOME};Home/Pos1][{END};END][{PGUP};Page UP][{PGDN};Page Down][{F1};F1][{F2};F2][{F3};F3][{F4};F4][{F5};F5][{F6};F6][{F7};F7][{F8};F8][{F9};F9][{F10};F10][{F11};F11][{F12};F12][{SPACE};Space]"
Local $HKT = _StringBetween($HKSTRING, "[", "]")
Global $HK, $HKS
Global $h_HotkeyTestInput
Dim $HK[0][2]                            ;Hotkey keys+names
Dim $HKS[6]                              ;Hotkey (ini)settings 0-3 combo boxes, 4 = Redirect the hotkey test to the input box, 5=Current Hotkey Set.

For $x = 0 To UBound($HKT) - 1            ;Make an array including the text from HKSTRING
    _ArrayAdd($HK, $HKT[$x], 0, ";")
Next

$HKT = ""
$HKSTRING = ""

SetHotkeyKeys(0)                    ;Set the initial hotkey
SetHotkeyKeys(1)                    ;Open the config-gui

while 1                 ;Test the hotkey. Output is in the console. Exit through traymenue.
    sleep (10)
WEnd

Func SetHotkeyKeys($showgui = 0)
    ;$showgui 0 = Set the saved hotkeys, 1 = Show gui to change the settings
    Local $a, $b, $c, $z
    $z=4                                                ;$z of the text from $HK will go in to c1-c3, the rest goes to c4
    $HKS[0] = IniRead($snip_inifile, "hotkey", "0", "4")
    $HKS[1] = IniRead($snip_inifile, "hotkey", "1", "0")
    $HKS[2] = IniRead($snip_inifile, "hotkey", "2", "0")
    $HKS[3] = IniRead($snip_inifile, "hotkey", "3", "12")
    $HKS[4] = 0
    $HKS[5] = $HK[$HKS[0]][0] & $HK[$HKS[1]][0] & $HK[$HKS[2]][0] & $HK[$HKS[3] + $z + 1][0]
    If $showgui = 1 Then
        $HKS[4] = 1
        #Region ### START Koda GUI section ### Form=
        $Form1 = GUICreate("Hotkey Config", 317, 79, -1, -1, $WS_POPUP + $WS_CAPTION)
        $C1 = GUICtrlCreateCombo("", 4, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
        $C2 = GUICtrlCreateCombo("", 82, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
        $C3 = GUICtrlCreateCombo("", 161, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
        $C4 = GUICtrlCreateCombo("", 239, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
        $Label1 = GUICtrlCreateLabel("Please set a hotkey to use. Note: Not all combos may work.", 4, 30, 300, 17)
        $Button1 = GUICtrlCreateButton("Set + Save", 4, 4, 70, 23)
        $h_HotkeyTestInput = GUICtrlCreateInput("Test", 82, 5, 150, 21)
        $Button2 = GUICtrlCreateButton("Exit", 239, 5, 72, 23)
        _GUICtrlComboBox_SetMinVisible($C4, 60)
        GUISetState(@SW_SHOW)
        #EndRegion ### END Koda GUI section ###

        For $x = 0 To UBound($HK) - 1
            If $x <= $z Then
                _GUICtrlComboBox_AddString($C1, $HK[$x][1])
                _GUICtrlComboBox_AddString($C2, $HK[$x][1])
                _GUICtrlComboBox_AddString($C3, $HK[$x][1])
            Else
                _GUICtrlComboBox_AddString($C4, $HK[$x][1])
            EndIf
        Next
        _GUICtrlComboBox_SetCurSel($C1, $HKS[0])
        _GUICtrlComboBox_SetCurSel($C2, $HKS[1])
        _GUICtrlComboBox_SetCurSel($C3, $HKS[2])
        _GUICtrlComboBox_SetCurSel($C4, $HKS[3])

        While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                Case $GUI_EVENT_CLOSE, $Button2
                    GUIDelete($Form1)
                    ExitLoop
                Case $Button1
                    $HKS[0] = _GUICtrlComboBox_GetCurSel($C1)       ;Read the combo - boxes
                    $HKS[1] = _GUICtrlComboBox_GetCurSel($C2)
                    $HKS[2] = _GUICtrlComboBox_GetCurSel($C3)
                    $HKS[3] = _GUICtrlComboBox_GetCurSel($C4)
                    HotKeySet($HKS[5])                              ;Clear the Old Hotkey
                    $HKS[5] = $HK[$HKS[0]][0] & $HK[$HKS[1]][0] & $HK[$HKS[2]][0] & $HK[$HKS[3] + $z +1][0]     ;Assemble the hotkey string, use $z+1 !
                    If HotKeySet($HKS[5], "DoHotkey") = 0 Then MsgBox(0, "Hotkey", "Err: Could not set. " & $HKS[5])        ;Set the hotkey or display a message
                    IniWrite($snip_inifile, "hotkey", "0", $HKS[0])                 ;Save the hotkey to the ini file
                    IniWrite($snip_inifile, "hotkey", "1", $HKS[1])
                    IniWrite($snip_inifile, "hotkey", "2", $HKS[2])
                    IniWrite($snip_inifile, "hotkey", "3", $HKS[3])
            EndSwitch
        WEnd
    EndIf

    If $HKS[4] = 0 Then                     ;Function was called with 0 
        $HKS[5] = $HK[$HKS[0]][0] & $HK[$HKS[1]][0] & $HK[$HKS[2]][0] & $HK[$HKS[3] + $z + 1][0]
        If HotKeySet($HKS[5], "DoHotkey") = 0 Then MsgBox(0, "Hotkey", "Err: Could not set. " & $HKS[5])
    Else
        $HKS[4] = 0
    EndIf
EndFunc   ;==>SetHotkeyKeys

Func DoHotkey()

    If $HKS[4] = 0 Then                 ;Main function
        ConsoleWrite("PRESS" & @CRLF)
    Else                                ;Gui test code:
        GUICtrlSetData($h_HotkeyTestInput, "Hotkey ! " & @hour & ":" & @min & ":" & @SEC)
    EndIf
EndFunc   ;==>DisplayActiveProcess

This script uses only 1 hotkey, and saves it  into an ini file.

To load and use the saved Hotkey from the ini use: SetHotkeyKeys(0) 

And to open the configuration window, use SetHotkeyKeys(1). 

Have fun.

Edited by Dan_555
Changed a variable to be global.

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TXTechie
      Hello Everyone,
      I've developed my own GUI using AutoIt and I'm allowing users to minimize the GUI, but I also want to include some kind of timer so that it will automatically restore the GUI after something like 30 minutes or an hour. However, I also want them to be able to manually restore the GUI by clicking the application's icon in the taskbar.
      I've searched through the forums, but I'm not sure how to get started.
      Any ideas or functions to research are appreciated!
      Regards,
      TX Techie
    • By Rskm
      Hi, recently i created a GUI for some calculations in AutoIT.  The GUI has 2 tabs and on the first tab, it has few inputboxes where i use to click with mouse and start entering the inputs. i recently made some changes in the position of these textboxes. I made this by changing the autoit code file instead of making changes in KODA. Now i cannot click inside these textboxes with mouse. However, i can use TAB key to cycle through/enter input in these input boxes. what could have made the inputboxes not responding to mouseclicks. thanks
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
    • By thedemons
      Introduction
      ImGui is a popular library written by ocornut, it can make awesome user interface based on directx. It is being used by many big apps/games.  The UI is nice and flexible, easy to use because of frame-by-frame drawing. So I decided to convert the entire ImGui library to AutoIt
      At first it's just an experiment, i converted some basic draw functions of imgui, compile to a dll, then using DllCall in autoit to call the functions. I was testing to see how much FPS i can get in autoit, and i was expected a low FPS, since autoit is slow. Suprisingly, the FPS turned out to be so high, it works really fast, even when drawing 1000 buttons at the same time. Features
      More than +270 functions converted from ImGui (compiled dll). Has 90% of the capability of what you can do in C++; Usable ImGuiIO and ImGuiStyle, so you can set whatever configurations you like. Preview
          
      Usage
      #include <WinAPI.au3> #include "ImGui.au3" ; Create a window Local $hwnd = _ImGui_GUICreate("AutoIt ImGui", 1024, 768) _WinAPI_ShowWindow($hwnd) ; Set style color _ImGui_StyleColorsLight() ;~ _ImGui_StyleColorsDark() Local $f_value = 5 While 1 ; when the user click close button on the window, this will return false if Not _ImGui_PeekMsg() Then Exit ; must call _ImGui_BeginFrame() _ImGui_Begin("Another window") _ImGui_Text("Hello there..") If _ImGui_Button("click me") Then $f_value = 5 _ImGui_SliderFloat("slider", $f_value, 2, 20) If _ImGui_IsItemHovered() Then _ImGui_ToolTip("what r u doing?") _ImGui_End() ; must call _ImGui_EndFrame() Wend  
      Remark
      Most of the functions were converted automatically. I haven't tested all of them yet, if some function doesn't work for you, please tell me. Still missing some features of ImGui, please tell me if you needed any. Run \tools\imgui-au3-setup.au3 to add _ImGui functions to SciTE auto-complete. Source Code
      Require: DirectX GitHub: imgui-autoit
    • By generic-username
      I've been trying to use the hotkey but it doesn't seem to work. The console log says "AU3 Check ended" thing everytime I run the script, it annoys the hell out of me. I'm quite new to AutoIt. Any help would be greatly appreciated.
      HotKeySet("a", "notepad") HotKeySet("b", "notepad") HotKeySet("c", "notepad") HotKeySet("d", "notepad") HotKeySet("e", "notepad") HotKeySet("f", "notepad") HotKeySet("g", "notepad") HotKeySet("h", "notepad") HotKeySet("i", "notepad") HotKeySet("j", "notepad") HotKeySet("k", "notepad") HotKeySet("l", "notepad") HotKeySet("m", "notepad") HotKeySet("n", "notepad") HotKeySet("o", "notepad") HotKeySet("p", "notepad") HotKeySet("q", "notepad") HotKeySet("r", "notepad") HotKeySet("s", "notepad") HotKeySet("t", "notepad") HotKeySet("u", "notepad") HotKeySet("v", "notepad") HotKeySet("w", "notepad") HotKeySet("x", "notepad") HotKeySet("y", "notepad") HotKeySet("z", "notepad") HotKeySet("{[}", "notepad") HotKeySet("{]}", "notepad") HotKeySet("{'}", "notepad") HotKeySet("{;}", "notepad") HotKeySet("{,}", "notepad") HotKeySet("{/}", "notepad") HotKeySet("{?}", "notepad") HotKeySet("{.}", "notepad") HotKeySet("{<}", "notepad") HotKeySet("{>}", "notepad") HotKeySet("{}}", "notepad") HotKeySet("{\}", "notepad") HotKeySet("{{}", "notepad") HotKeySet("{|}", "notepad") HotKeySet("{=}", "notepad") HotKeySet("{+}", "notepad") HotKeySet("{-}", "notepad") HotKeySet("{_}", "notepad") HotKeySet("{(}", "notepad") HotKeySet("{)}", "notepad") HotKeySet("{*}", "notepad") HotKeySet("{&}", "notepad") HotKeySet("{^}", "notepad") HotKeySet("{%}", "notepad") HotKeySet("{$}", "notepad") HotKeySet("{#}", "notepad") HotKeySet("{@}", "notepad") HotKeySet("{!}", "notepad") HotKeySet("{`}", "notepad") HotKeySet("{~}", "notepad") HotKeySet("{1}", "notepad") HotKeySet("{2}", "notepad") HotKeySet("{3}", "notepad") HotKeySet("{4}", "notepad") HotKeySet("{5}", "notepad") HotKeySet("{6}", "notepad") HotKeySet("{7}", "notepad") HotKeySet("{8}", "notepad") HotKeySet("{9}", "notepad") HotKeySet("{0}", "notepad") Func notepad() Run("notepad.exe") EndFunc  
×
×
  • Create New...