Build Your Own Arcade Controls Forum

Main => Main Forum => Topic started by: griffindodd on November 28, 2012, 11:39:19 pm

Title: Need AHK script to run .bat file from key combination
Post by: griffindodd on November 28, 2012, 11:39:19 pm
HI guys,

I need to execute a .bat script that I use to rotate my monitor by hitting a shifted key combination on my control panel.

e.g

- Shifted P1 Joystick left initiates my 'Portrait Mode' .bat script
- shifted P1 Joystick right initiates my 'landscape Mode' .bat script

I'm pretty bad at AHK can anyone help me out?
Title: Re: Need AHK script to run .bat file from key combination
Post by: BadMouth on November 29, 2012, 09:09:19 am
What button does "Shifted P1 Joystick left" post as in windows?
Title: Re: Need AHK script to run .bat file from key combination
Post by: griffindodd on November 30, 2012, 10:44:31 pm
Shifted P1 left is 'm'
Shifted P1 right is 'n'

I have two scripts, one for each direction called landscape.bat and portrait.bat
Title: Re: Need AHK script to run .bat file from key combination
Post by: darthpaul on November 30, 2012, 11:11:37 pm
If you are using MALA, why not just automate it using MRotate?
Title: Re: Need AHK script to run .bat file from key combination
Post by: griffindodd on November 30, 2012, 11:14:02 pm
I'm using Hyperspin
Title: Re: Need AHK script to run .bat file from key combination
Post by: BadMouth on December 01, 2012, 07:49:42 am
Code: [Select]
m::
run, portrait.bat

n::
run, landscape.bat

return

Copy and paste that into notepad and save it as a .ahk file type.

portrait.bat and landscape.bat will need to be in the same folder as the ahk script as it is written, or you can specify the full path to them and it won't matter where they are.
Put a shortcut to the script in your startup folder if you boot into windows normally and haven't set up Hyperspin as your shell.
It will run all the time.  If you want to exit the script, you'll have to  right click on the autohotkey icon in your system tray (bottom right of desktop) and exit it that way.

If you need more help with autohotkey, post in the software forum. 
It will probably get answered faster by people who know more than me.  ;D
Title: Re: Need AHK script to run .bat file from key combination
Post by: brad808 on December 01, 2012, 09:46:25 am
Just out of curiosity what is inside your bat file? I'm also looking to create a one button rotate from landscape to portrait and wondering how you went about it.
Title: Re: Need AHK script to run .bat file from key combination
Post by: BadMouth on December 01, 2012, 11:00:20 am
Just out of curiosity what is inside your bat file? I'm also looking to create a one button rotate from landscape to portrait and wondering how you went about it.

just the command line that tells the pololu simple motor controller to move.  (last number is negative for opposite direction)

@echo off
smccmd --speed -3200

The commands don't work directly in ahk. see below
I downloaded a pdf booklet about using ahk with the pololu, but haven't looked at it.
There might be a way to do it directly from the ahk script.

I'm very happy with the simple motor controller. (thanks TopJimmyCooks!)
It's USB and should work with new operating systems for years to come.
Only hiccup I had was understanding how to set up the limit switches in the software.
Even with that, I had it installed (which involved pulling and reinstalling the monitor mount in my cab)
and my monitor controlled by Mala set up within a couple hours.

EDIT: a quick look at the Pololu ahk guide and it turns out that the commands can be run directly, just need to put "run" in front of them (no comma)
Haven't tested it, but it should go like this.....

Code: [Select]
m:: run smccmd --speed -3200,,Hide

n:: run smccmd --speed 3200,,Hide

return
CORRECTED: Per Griffinddd's post below (In case anyone is just glancing through the thread and misses it)
Title: Re: Need AHK script to run .bat file from key combination
Post by: Le Chuck on December 01, 2012, 03:12:41 pm
Just out of curiosity what is inside your bat file? I'm also looking to create a one button rotate from landscape to portrait and wondering how you went about it.

just the command line that tells the pololu simple motor controller to move.  (last number is negative for opposite direction)

@echo off
smccmd --speed -3200

The commands don't work directly in ahk. see below
I downloaded a pdf booklet about using ahk with the pololu, but haven't looked at it.
There might be a way to do it directly from the ahk script.

I'm very happy with the simple motor controller. (thanks TopJimmyCooks!)
It's USB and should work with new operating systems for years to come.
Only hiccup I had was understanding how to set up the limit switches in the software.
Even with that, I had it installed (which involved pulling and reinstalling the monitor mount in my cab)
and my monitor controlled by Mala set up within a couple hours.

EDIT: a quick look at the Pololu ahk guide and it turns out that the commands can be run directly, just need to put "run" in front of them (no comma)
Haven't tested it, but it should go like this.....

Code: [Select]
m::run smccmd --speed -3200,,Hide

n::run smccmd --speed 3200,,Hide

return
(letters may be flipped depending on which way your monitor rotates...your speed may vary)

I need to go back and rework by TRON script if that's the case.  Eliminating the bat files would stream line things a bit.  No real change in performance but it's nice to have a one file solution. 
Title: Re: Need AHK script to run .bat file from key combination
Post by: BadMouth on December 01, 2012, 03:44:26 pm
Here is a link to the Pololu AHK guide:
http://www.pololu.com/docs/0J45 (http://www.pololu.com/docs/0J45)

You can download a pdf at the top.  It's only 8 pages.
Title: Re: Need AHK script to run .bat file from key combination
Post by: griffindodd on December 03, 2012, 02:20:28 pm
Thanks for this guys, haven't had chance to fart this weekend but I'll give it a try when I get a chance.
Title: Re: Need AHK script to run .bat file from key combination
Post by: griffindodd on December 06, 2012, 11:55:44 pm
Almost right, you need a space before the run command like this

Code: [Select]
m:: run smccmd --speed -3200,,Hide

n:: run smccmd --speed 3200,,Hide

return
Title: Re: Need AHK script to run .bat file from key combination
Post by: DaOld Man on December 11, 2012, 03:20:48 pm
Is it possible to read key presses with AHK? This could help folks who are using this method but need switched inputs to tell the PC which orientation the monitor is in. If you have some unused inputs on your keyboard emulator (keywiz, etc), you could get input through those.
Title: Re: Need AHK script to run .bat file from key combination
Post by: BadMouth on December 11, 2012, 03:33:32 pm
Is it possible to read key presses with AHK? This could help folks who are using this method but need switched inputs to tell the PC which orientation the monitor is in. If you have some unused inputs on your keyboard emulator (keywiz, etc), you could get input through those.

Autohotkey's power is limitless!   :notworthy:
http://www.autohotkey.com/docs/commands/GetKeyState.htm (http://www.autohotkey.com/docs/commands/GetKeyState.htm)

After you modified Malaori3 for me, someone turned me onto the iniswap command in ahk.
It swaps variables into ini files.