AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

My HotKeys GUI

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
gb
Guest





PostPosted: Sun Jun 19, 2005 6:14 pm    Post subject: My HotKeys GUI Reply with quote

Dear all,

This is my attempt at producing a HotKeys GUI. Being still new at using AHK, I guess there are probably better HotKeys GUI scripts available already, but this is an exercise in learning by doing for me.

It is a new script and not yet fully tested, although I've been using most of today and it seems to work without many problems.

I would appreciate any constructive help and advice. I'm afraid I am quite sensitive, so please rather don't reply if you're not going to contribute something helpful or useful. Wink

I am reading the help file, but I am finding the GUI information hard to understand, and what I think I understand has not seemed to work in practice. No criticism of the help documentation is intended - I think the limitation is in my reading and understanding. Crying or Very sad

I cannot understand how to create and use more than one GUI window in a script. I also cannot figure out how to sort the listbox so that duplicates of the hotkeys will be removed.

So my HotKeysGUI is actually two scripts - HotKeysGUI (the main window) and HKGuiEdit (the secondary window). The operation of these two scripts produces a third script called HKmain.ahk, which contains all the hotkeys and which is run automatically on exiting the main HotKeysGUI window.

I also make use of two "config" files which are "pre-pended" and "post-pended" to the HKmain.ahk file, and which add certain config thing-ies that I like to have.

I'm afraid for now these scripts are not well-documented and there are not many explanations or descriptions in the scripts as I'm still figuring out a lot of what I'm doing - I hope to post more later.

The files and scripts must be called HotKeysGUI.ahk, HkGuiEdit.ahk, HKconfig1.txt and HKconfig2.txt. The scripts are configured to use the working directory (A_WorkingDir), so I hope they will work wherever you put them. Just save them all to whaever you use as your working directory, and (obviously) include a shortcut to HKmain.ahk in your startup folder if you want the hotkeys to be available on Windows startup.

The main script creates a file HKlist.csv which stores the hotkey definitions - if you make a good backup copy, you will be able to recover your hotkeys in the event of something untoward happening.

My thanks to mallow, whose HotStringsGUI ver 0.2 was the inspiration for me to attempt this. Smile

Known limitations:
I've tried to keep it siomple, so the hotkeys here don't test for multiple instances of a program - if you keeping hitting the hotkeys to launch IE, for example, you will run multiple copies of IE (personally, this is a feature for me).

Also, if you change your mind about adding a hotkey, do check that a blank line or a ` hasn't been inserted as it will crash HKmain.

Similarly, you might be able to use the same hotkeys twice, although I've tried to make this difficult.

Here are the scripts - I hope they will be of some use to someone else also:

HotKeysGUI.ahk:
Code:

; HotKeysGUI - main window
; Generated using SmartGUI Creator 3.5
; AHK ver 1.0.35x
; ====================================
#SingleInstance force
SetTitleMatchMode, 2
SetTitleMatchMode, slow

Gui, Add, ListBox, vMyListBox gMyListBox x16 y7 w440 h190 Sort U,
Gui, Add, Button, vButtonAdd x16 y247 w90 h30,Edit 
Gui, Add, Button, vButtonDelete x116 y247 w90 h30,Delete   
Gui, Add, Button, vButtonDone x216 y247 w90 h30,Done   

Loop, read, %A_WorkingDir%\HKList.csv
{
  GuiControl, , MyListBox, %A_LoopReadLine%
}

Gui, Show, x270 y110 h288 w473, HotKeysGUI - copyright 2005, gb
Return

MyListBox:
If A_GuiControlEvent <> DoubleClick
   return
GuiControlGet, MyListBox
FileDelete, %A_WorkingDir%\~temp.csv
FileAppend, %MyListBox%, %A_WorkingDir%\~temp.csv
Gosub, ButtonDelete
Run, %A_workingDir%\HKGuiEdit.ahk
Gosub, ButtonDone
Return

ButtonEdit:
GuiControlGet, MyListBox
FileDelete, %A_WorkingDir%\~temp.csv
FileAppend, %MyListBox%, %A_WorkingDir%\~temp.csv
Gosub, ButtonDelete
Run, %A_workingDir%\HKGuiEdit.ahk
Gosub, ButtonDone
ExitApp

ButtonDelete:
GuiControl, +AltSubmit, Listbox1
GuiControlGet, Item, , Listbox1
Control, Delete, %Item%, Listbox1
GuiControl, -AltSubmit, Listbox1
Return

ButtonDone:
GuiClose:
FileDelete, %A_WorkingDir%\HKList.csv
FileDelete, %A_WorkingDir%\HKmain.ahk
FileRead, Config1, %A_WorkingDir%\HKConfig1.txt
FileRead, Config2, %A_WorkingDir%\HKConfig2.txt

ControlGet, List, List,, Listbox1, A
FileAppend, %List%, %A_WorkingDir%\HKList.csv
FileAppend, %Config1%`r`n`r`n; == HotKeys Begin Here ==`r`n`r`n, %A_WorkingDir%\HKmain.ahk

Loop, read, %A_WorkingDir%\HKList.csv
{
   Loop, parse, A_LoopReadLine, CSV
   {
      Var%A_Index% = %A_LoopField%
   }
FileAppend, %Var1%`::Run`, %Var2%`n, %A_WorkingDir%\HKmain.ahk
}

FileAppend, `r`n`r`n;== HotKeys End Here ==`r`n`r`n%Config2%`r`n, %A_WorkingDir%\HKmain.ahk
Run, %A_WorkingDir%\Hkmain.ahk
ExitApp


HKGuiEdit.ahk:
Code:

; HKGuiEdit - Secondary Window
; Generated using SmartGUI Creator 3.5
; AHK ver 1.0.35x
; ====================================
#SingleInstance force

SetTitleMatchMode, 2
SetTitleMatchMode, slow

Gui, Add, Edit, vEditHK1 x15 y6 w100 h30 ,
Gui, Add, Edit, vEditHK2 x15 y36 w330 h30 ,
Gui, Add, Button, x146 y77 w100 h30, &Done
Gui, Add, Text, x116 y7 w220 h20,Use ! for Alt`, ^ for Ctrl`, + for Shift and # for Win
Gui, Add, Button, vProg gProg x346 y27 w50 h20,... Prog
Gui, Add, Button, vFolder gFolder x346 y47 w50 h20,...Folder
Gui, Show, x265 y175 h120 w406, HotKeysGUI-Edit - copyright 2005, gb
Loop, read, %A_WorkingDir%\~temp.csv
{
   Loop, parse, A_LoopReadLine, CSV
   {
      Var%A_Index% = %A_LoopField%
   }
Control, EditPaste, %Var1%, Edit1, A
Control, EditPaste, %Var2%, Edit2, A
}
Return

Prog:
FileSelectFile, TheFile, S3, %A_workingDir%, Choose file or program, *.*
Control, EditPaste, %TheFile%, Edit2, A
Return

Folder:
FileSelectFolder, TheFolder, %A_WorkingDir%, 3, Select folder
Control, EditPaste, %TheFolder%, Edit2, A
Return

ButtonDone:
Gui, Submit, NoHide
GuiControlGet, EditHK1  ; Retrieve the HotKey value
GuiControlGet, EditHK2  ; Retrieve the HotKey parameters
FileAppend, `n%EditHK1%`,%EditHK2%`n, %A_WorkingDir%\HKList.csv  ; Save the contents to the file.
GuiControl,, EditHK1
GuiControl,, EditHK2
FileDelete, %A_WorkingDir%\~temp.csv

GuiClose:
Run, %A_WorkingDir%\HotKeysGUI.ahk
ExitApp


HKconfig1.txt:
Code:

; HKconfig1.txt - first config file
; Generated by HotKeysGUI
; Copyright 2005, gb
; AHK ver 1.0.35x
; ========================
; Config Section
; ========================
#SingleInstance force

SetTitleMatchMode, 2
SetTitleMatchMode, Slow

; ========================
; Create Menus
; ========================
Menu, tray, add, ScriptWriter
Menu, tray, add ; separator
Menu, tray, add, HotKeysGUI
Return


HKconfig2.txt:
Code:

; HKconfig2.txt - second config file
; =============
; Menu Items
; =============

ScriptWriter:
  Run, C:\Program Files\AutoHotkey\AutoScriptWriter\AutoScriptWriter.exe
Return

HotKeysGUI:
  Run, C:\AHK Work\Scripts\HotKeysGUI.ahk ;Run HotKeysGui
Return
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Jun 21, 2005 1:36 pm    Post subject: Re: My HotKeys GUI Reply with quote

gb wrote:
I cannot understand how to create and use more than one GUI window in a script.
Try reading the section about "multiple windows" again. It basically amounts to the fact that every command can be prefixed with a window number:
Gui, 2:Add, Text,, This text is added to the second GUI window.
Gui, 2:Show

You can avoid having to specify the number each time by specifying Gui, 2:Default prior to a series of GUI commands.

Quote:
I also cannot figure out how to sort the listbox so that duplicates of the hotkeys will be removed.
You could use the Sort command to eliminate duplicates from the list.

Thanks for sharing your script.
Back to top
View user's profile Send private message Send e-mail
zridling



Joined: 28 Jun 2005
Posts: 9
Location: St. Louis, US

PostPosted: Tue Jun 28, 2005 6:57 am    Post subject: Reply with quote

This was nice. I'm a new user and this helped!
_________________
- Zaine Ridling, THE GREAT SOFTWARE LIST
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group