# Playing with HotKeys and keyboard shortcuts using AutoKey. 10 step guide.



## firestormer

I have a Dell Laptop. It has an annoying little hotkey button that i wanted to re-asign to Media Center and not to use 'Dell Quick Set'. I also didn't want to download a full program to do this.

But i can across a program called AutoHotKey. This is an autoit based program that helps you to write your own scripts and compile them to programs to manage hotkeys.

Bellow is a simple step by step guide to creating a script using AutoHotKey for a special keyboard button which is currently unassigned.

1. Download and install AutoHotKey from http://www.autohotkey.com/download/

2. Open notepad and enter the following 


Code:


#InstallKeybdHook

Save the file as KeyHook.ahk and close notepad
This will help you grap the keys id code for use latter.

[DURING STEPS 3 -7 DO NOT ENTER ANY PASSWORDS INTO YOUR COMPUTER AS THE SCIPT IS DESIGNED TO RECORD YOUR KEYSTROKES SO THAT YOU CAN IDENTIFY YOUR HOTKEY]

3. Run the new file you just created by double clicking its icon
You will notice a green icon with a H appears in your system tray, double click it.

4. A window will appear, in the window click View> Key History and Script Info

5. The window will change and it will show a list of the keys pressed since you started the script.
Press your hot key now
Press F5

6. The window will have refreshed and at the bottom you will see somwthing like this:


Code:


54  014	 	d	4.77	T     
54  [B][COLOR="Red"]014	[/COLOR][/B] 	u	0.09	T              	
74  03F	 	d	0.75	F5             	
Press [F5] to refresh.

In this case I pressed T as an example. But in your case it will show your hotkey. (Note: In the key column it may show a letter, ignore this)
Make a note of the value in the second column as i have shown in red for my case.

7. Go File>Exit

8. Open notepad and paste in the following:


Code:


#NoTrayIcon
SC[COLOR="Red"]112[/COLOR]::
Run [COLOR="Blue"]%SystemRoot%\ehome\ehshell.exe[/COLOR]
return

Replace the number in red with your own from earlier and the text in blue with the path of the programm you want to run.
(Note: If it is not a special key replace the whole SC112 with the appropriote key found here: http://www.autohotkey.com/docs/KeyList.htm)

9. Save the script as whatever you want but with an .ahk file extension. eg HotKey.ahk

10. Use 'Convert .ahk to .exe' found in Start > All Programs > AutoHotKeys and compile it to an appropriate location. If you want you can then add it to startup by placing it in Start> Programs > Startup

By placing it in the startup folder the script will run when you logon allowing you to use the hotkey to open your specified program. There is no visible evidence that the program is running while it runs. To exit the program once launched you will need to open Task Manager (Ctrl + Alt + Dlt) go to proccesses locate the program by the name you saved it as , right click on it and click 'End Proccess'


----------



## stantley

Handy little tip. You ran across one of my favorite programs, AutoHotkey. I think you'll find all sorts of uses for it.

I've been using it for about 3 years now and I keep finding different ways to use it. It's great for almost any kind of repetitive task. There's a little bit of a learning curve but it's very intuitive.

The other good thing is the user forum, whenever I've been stuck on a script I've posted the question and had the answer very quickly. They also have a lot of interesting scripts out there.


----------



## ferrija1

stantley said:


> Handy little tip. You ran across one of my favorite programs, AutoHotkey. I think you'll find all sorts of uses for it.
> 
> I've been using it for about 3 years now and I keep finding different ways to use it. It's great for almost any kind of repetitive task. There's a little bit of a learning curve but it's very intuitive.
> 
> The other good thing is the user forum, whenever I've been stuck on a script I've posted the question and had the answer very quickly. They also have a lot of interesting scripts out there.


I remember when you posted a while ago, I got it then and it's great.


----------



## stantley

Cool  :up:


----------



## Archaen

wow, thanks alot, but now it opens media centre and media direct


----------



## firestormer

This is probably because you've still got Dell Quick Set running. All the program youve created does is watch for you to press the MD button as does Dell Quick Set.

I sugest you disable/remove Dell Quick Set form Startup or uninstall it completely.


----------



## Archaen

firestormer said:


> This is probably because you've still got Dell Quick Set running. All the program youve created does is watch for you to press the MD button as does Dell Quick Set.
> 
> I sugest you disable/remove Dell Quick Set form Startup or uninstall it completely.


thanks very much


----------



## firestormer

No problem (he says 2 months later)


----------



## dickiedum

Thanks for the tip. I have had loads of problems with Dells media button. It now refuses to even recognise the cd. After using your guide my media button now works and runs windows media centre. Result. Cheers very very much.:up:


----------



## firestormer

Always glad to help


----------



## Xichael

Thanks for the tutorial. I've been eager to get that MediaDirect button to do something. I got it working with AutoHotkey, but I'd really prefer working with AutoIt. I see from this thread that you've experimented with AutoIt. Have you tried the above recipe in AutoIt?

So far I've figured out how to launch a program by hotkey:



Code:


#NoTrayIcon

HotKeySet ("YourHotKeyGoesHere", "AnyFuncNameGoesHere")

While 1
	Sleep(50)
WEnd
  
Func AnyFuncNameGoesHere()
    Run("C:\Program Files\YourProgram.exe")
EndFunc

The only problem is with getting AutoIt to read the the SC112 keystroke. Did you abandon AutoIt for this reason? Does it just not work with weird keys like SC112?

Any insight is appreciated...


----------



## firestormer

Autohotkey is base on autoit, just modified slightly for keyboard input


----------



## Xichael

So I finally figured out how to do this in AutoIt... The MediaDirect button is *FF* with an _IsPressed, and would be *255* with a HotKeySet (or Chr(255) in use) if I could get it to work. Here's an example script (just replace the program path/file):


Code:


#NoTrayIcon

#include <misc.au3>

While 1
    If _IsPressed("FF") Then
        YourFuncNameHere()
    EndIf
    Sleep(50)
WEnd

Func YourFuncNameHere()
    Run ("C:\Program Files\YourProgramHere.exe")
EndFunc


----------



## axeman61

If autohotkey is derived from autoit, then is one better than the other?


----------



## stantley

axeman61 said:


> If autohotkey is derived from autoit, then is one better than the other?


That's the subject of a heated debate http://www.autohotkey.com/forum/topic4363.html

I think Chris Mallett, the author of AutoHotkey, summed it up best:


> I think both languages are similar in terms of syntax capabilities. Which one to use is largely a matter of personal preference, and also which one you learned first.


For me, I think AutoHotkey is a little easier to learn and the AHK forum has been very helpful with any questions I've had.


----------



## JohnWill

I've used AutoIt for years, and it's always worked well for me. I never had any issues learning how to use it.

Just an opposing opinion.


----------



## lagunijus

so... I have such problems with inspiron 1520 too...
few monts ago I byed a new laptop. because I hate windows vista, at first i created windows xp sp3 boot disk with sata and other drives (with nlite) and deleted all partiotions from hdd. then created primary ntf for win xo, primary the for linux and for logical common uses (movies and etc). that was ok for some time. I but some-how I pressed dell's media direct button - and this sh1t destroyed my all file systems. Ok, then I reinstaled all my systems. Some days ago, my 2 years kid fouded my laptop on the table, and pressed this button again.... #$***^^%% !!!!
So... then I under the linux bootable dvd formated the disk drive with low level, and then installed test windows xp version. but media direct still appiers. seems this evil (MD 3.*) is located somwhere in bios or something. then i decited to turn of this button. I opened a small cover and cuted the wire in plate. It tooks for me about 30 minutes (now I could do this durring 15 mins). Now i thing everything will be ok


----------



## ferrija1

I hope it is, that sounds terrible.


----------



## firestormer

Xichael said:


> Thanks for the tutorial. I've been eager to get that MediaDirect button to do something. I got it working with AutoHotkey, but I'd really prefer working with AutoIt. I see from this thread that you've experimented with AutoIt. Have you tried the above recipe in AutoIt?
> 
> So far I've figured out how to launch a program by hotkey:
> 
> 
> 
> Code:
> 
> 
> #NoTrayIcon
> 
> HotKeySet ("YourHotKeyGoesHere", "AnyFuncNameGoesHere")
> 
> While 1
> Sleep(50)
> WEnd
> 
> Func AnyFuncNameGoesHere()
> Run("C:\Program Files\YourProgram.exe")
> EndFunc
> 
> The only problem is with getting AutoIt to read the the SC112 keystroke. Did you abandon AutoIt for this reason? Does it just not work with weird keys like SC112?
> 
> Any insight is appreciated...


Sorry got a little side tracked. When i was using AutoIt i was just being sneaky and replaceing Dell program with and autoIt program of my own with the same name. I didn't realy look into AutoIt for capturing keys i came across AutoHotkey not realising it was derived from autoIt untill i started using it.


----------

