Showing posts with label Auto Hot Key. Show all posts
Showing posts with label Auto Hot Key. Show all posts

Saturday, June 6, 2015

AutoHotKey

A while ago I wanted to find a way to create keyboard short-cuts that weren't available out of the box for my windows PC. Looking around, I came by AutoHotKey (AHK) which seems to not only allow for keyboard short-cuts, but much more. AHK allows you to control all sorts of things on your PC, be it through keyboard inputs, or through scripts running on your machine that pick up changes on the PC to be used in any way you like. 

AutoHotKey can be downloaded here:
After installation it is a simple matter of right clicking a script file and selecting “compile script” to create an executable from it.

The main reason I started using AHK was for helping me use my harmony universal remote to control my PC, and mainly, to use it to open and control my PLEX client. More on this can be found here:

This brings me to my first script, which was naturally, opening the PLEX home theater:
This one uses a SHIFT+ALT+F10 key combination to open the file in:
“C:\Program Files (x86)\Plex Home Theater\Plex Home Theater.exe”, if the PLEX Home Theater executable isn't already running.

Here are the rest of the scripts I've written since then:

KeyPad-Letters: This had to do with my problem finding a way to enter letters in the PLEX search box from my remote, which had only a numpad.
So, with the help of this script, I essentially created a phone-like numpad. The script sends letters while pressing the number buttons of the remote repeatedly like you usually do on the TV or older phones with no keyboard.
So, for instance, if I want to write abg3 I'll be able to do that with the remote by: pressing 2, wait a second (or press Alt-Shift-F8), pressing 2 twice, pressing 4 once, pressing 3 four times.
the Keypad-Letters script can be found at:
This script also uses Alt-Shift-F8 (which I mapped through FLIRC, as explained in the other blog post I mentioned earlier) to stop the 1 second timer so that you could write other characters from the same number immediately without having to wait a second between each letter.

Close Display: By far my most used keyboard short-cut, this one uses WIN-q to close my PC’s display screen just as it would when the computer usually goes to sleep or shuts down. This is extremely useful when you've left your PC for a little while, and don’t want it to go to sleep or shut down. It saves power used by the display, and also protects it from being “burned” if your screen-saver takes a while to start. In general, it makes me feel better knowing that my display isn't sitting there waiting for someone who is not around.

Change Resolution: This script uses WIN-w to immediately set your current display to use a resolution of 1920 x 1200 (which is what my PC display should be using). This was useful to me when using PLEX, as it was run on my 1080p TV, and would sometimes keep my other display in this same resolution after I closed PLEX.

Change PC volume by resolution: This script listens to a resolution change event from the windows operating system, and sets the PC’s volume accordingly. As it happened, the volume I heard on my PC’s headphones was much louder than that heard from my other audio output to my receiver, which was used when watching PLEX on my 1080p TV. Instead of always increasing the volume manually, I created this script to automatically change the volume when my resolution was set to 1080p (which automatically happens when starting PLEX in my case).

One script to include them all (and in a single executable run them):
In order to run all these scripts together, and not as separate executables, I created one other script which essentially includes all the rest. This is simply done by creating another AHK script file that has this:
#Include c:\full\path\to\ahk\script\file\to\be\included.ahk

And to finish this whole thing off, I’ll give you a small tip on how to run scripts that need admin rights. Sometimes, you want a keyboard shortcut in AHK to run a program that needs admin rights. Instead of having to authorize to use it with admin rights every time you run the keyboard shortcut for it, you could run a VBS script that would require the admin rights only once (on startup for instance). After doing it once, it will keep those rights as long as it runs. Saving you unnecessary clicks and hassles. Of course, be wary not to give your admin rights away to any third party executable you know nothing about.
Just create a file with a “vbs” extension, such as ahk_scripts.vbs and add these lines:

Set UAC = CreateObject("Shell.Application") 
UAC.ShellExecute " c:\full\path\to\ahk\executable\to\run\with\admin\rights.exe", "", "", "runas", 1


 As you can see, AHK lets you have a lot more power over your PC. Almost anything you want to do with your PC has a way to do it, and I hope the examples above will give you a few good tools to start building the scripts you need.



Saturday, August 23, 2014

Plex + FLIRC + harmony

Here's my account on how I went about configuring the Plex Home Theater with FLIRC and a harmony ultimate.

I decided to have a look at PLEX since i'm going to be moving to an apartment where the PC will be connected directly to the TV. Since it will be directly connected, I won't be using my streamer, and I thought I should look into using a nice looking media player/server.

Already having a harmony ultimate remote, I looked around for various ways to get it to control the PLEX Home Theater, and i decided on FLIRC.

FLIRC is a cool piece of USB driven hardware that translates IR (Infra-Red) signals to keyboard clicks. Since it does the translating for you, it means the PC/Streamer or whatever you're using it on doesn't need to know anything about IR translation, It gets normal keyboard inputs as if from a regular keyboard.

In order to configure the harmony remote to control PLEX I used the old approach that doesn't include the FLIRC-PLEX profile in the harmony remote. Using this approach, we configure the harmony with a device that has a lot of IR codes that are different from one another. This approach lets me do all sorts of things with keyboard shortcuts, namely using AutoHotKey (AHK) to configure commands not in the PLEX command list.
Here's a word document with my mappings using the Panasonic TC-P65VT30 device in the harmony remote:

About the AHK scripts:
The script that directly affects PLEX, and is aptly named StartPlex.ahk, always runs on the PC (it is in my startup folder) and the extra keyboard shortcuts in it do this:
Alt-Shift-F10 - opens the plex client (theater)
It expects the PLEX Home Theater to be in:
“C:\Program Files (x86)\Plex Home Theater\Plex Home Theater.exe”. if it is not in the same location on your PC, change the ahk file and recompile it to create the executable (literally 2 clicks once you have AHK installed).

other than this one script, i urge you to have a look at my other scripts since they may fit your particular case as they did mine (posted here: http://programming-headbanging.blogspot.co.il/2015/06/awhile-ago-i-wanted-to-find-way-to.html)
. Things such as changing the PC volume automatically when starting PLEX, or changing the PC resolution with a keyboard click.
All my scripts are updated in this post:
 Now, all that's left is to sit back, click the PLEX activity on the remote and watch TV till we drop.