Developer's Blog
Register Low Fi Mark Forums Read

Rate this Entry

How to make hotkey tool

Posted 10-15-2011 at 09:59 AM by AucT

Hello guys! Im going to tell u how to create simple autohotkey script. It will be some advanced version of EasyPack. It will include 3 steps.
1. Creating Basic Tool
2. Adding interface
3. Adding special functions

NOTE: Autohotkey script will work only in windows.

You will need:
1) Autohotkey
2) some text editor

Step 1 : Creating Basic Tool
To create autohotkey script simply rightlick mouse - create autohotkey script or save text file in .ahk extension.

Header
First of all we need make some changes in the options of the script so in the header we will put this preferences:
Code:
#SingleInstance force
#HotkeyInterval 0
#InstallKeybdHook
#UseHook On
#MaxThreads 25
SetBatchLines, -1
SetKeyDelay , -1, -1
SetDefaultMouseSpeed, 0
SetMouseDelay, -1
Process, priority, , High
SetWorkingDir %A_ScriptDir%
#NoEnv
#ifWinActive, ahk_class Warcraft III
Setting Keys
Now we will read the .ini file. If it doesnt exist we will get default hotkeys (alt+q; alt+w, alt+a, alt+s, alt+z, alt+x).
I used variables h1-h7 for future purposes (detecting same variable).
I would like all hotkeys iniread and hotkey via loop, but for better understanding I will make loop only for item hotkeys and for pause script I will do it manually. To do that we will read our ini file, and if key not a blank - we will create hotkey

This is how to do in the loop. Mb it is a bit advanced for you now.
Code:
  loop {
  IniRead, h%A_Index%, %A_WorkingDir%\EasyPack2.ini, Inventory, item%A_Index%, %A_Space%
  if % h%A_Index%
  Hotkey, % h%A_Index%, a%A_Index%
  if A_Index=6
	break
  }
Here how to simply make hotkey
Code:
IniRead, h7, %A_WorkingDir%\EasyPack2.ini, Other, Pause, Home
  if h7
  Hotkey, %h7%, a7
Basic labels
Here our labels. I used names a - action so in next steps we can easily put it all to the loop

Code:
a1:
send {vk67}
return

a2:
send {vk68}
return

a3:
send {vk64}
return

a4:
send {vk65}
return

a5:
send {vk61}
return

a6:
send {vk62}
return

a7:
suspend
return
Final code for step 1:
Code:
#SingleInstance force
#HotkeyInterval 0
#InstallKeybdHook
#UseHook On
#MaxThreads 25
SetBatchLines, -1
SetKeyDelay , -1, -1
SetDefaultMouseSpeed, 0
SetMouseDelay, -1
Process, priority, , High
SetWorkingDir %A_ScriptDir%
#NoEnv
#ifWinActive, ahk_class Warcraft III

  loop {
  IniRead, h%A_Index%, %A_WorkingDir%\EasyPack2.ini, Inventory, item%A_Index%, %A_Space%
  if % h%A_Index%
  Hotkey, % h%A_Index%, a%A_Index%
  if A_Index=6
	break
  }
  
  IniRead, h7, %A_WorkingDir%\EasyPack2.ini, Other, Toggle, Home
  if h7
  Hotkey, %h7%, a7
return
  
a1:
send {vk67}
return

a2:
send {vk68}
return

a3:
send {vk64}
return

a4:
send {vk65}
return

a5:
send {vk61}
return

a6:
send {vk62}
return

a7:
suspend
return
Attached Files
File Type: zip Step 1 - EasyPack2.zip (198.2 KB, 192 views)
Posted in Guides
Views 1462 Comments 0 Email Blog Entry
Total Comments 0

Comments