Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Need AHK script to run .bat file from key combination  (Read 5711 times)

0 Members and 1 Guest are viewing this topic.

griffindodd

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1514
  • Last login:June 29, 2023, 02:43:19 pm
  • Builds Stuff
Need AHK script to run .bat file from key combination
« 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?
« Last Edit: November 28, 2012, 11:40:55 pm by griffindodd »
I drink and I know things.

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9226
  • Last login:June 13, 2024, 01:06:22 pm
  • ...
Re: Need AHK script to run .bat file from key combination
« Reply #1 on: November 29, 2012, 09:09:19 am »
What button does "Shifted P1 Joystick left" post as in windows?

griffindodd

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1514
  • Last login:June 29, 2023, 02:43:19 pm
  • Builds Stuff
Re: Need AHK script to run .bat file from key combination
« Reply #2 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
I drink and I know things.

darthpaul

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 447
  • Last login:November 23, 2022, 07:34:53 pm
  • Join, It's your duty
Re: Need AHK script to run .bat file from key combination
« Reply #3 on: November 30, 2012, 11:11:37 pm »
If you are using MALA, why not just automate it using MRotate?
"You don't know the power of the Dark Side"
Automated Cabinet
Nintendo Pi
PiCubed

griffindodd

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1514
  • Last login:June 29, 2023, 02:43:19 pm
  • Builds Stuff
Re: Need AHK script to run .bat file from key combination
« Reply #4 on: November 30, 2012, 11:14:02 pm »
I'm using Hyperspin
I drink and I know things.

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9226
  • Last login:June 13, 2024, 01:06:22 pm
  • ...
Re: Need AHK script to run .bat file from key combination
« Reply #5 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
« Last Edit: December 01, 2012, 07:53:37 am by BadMouth »

brad808

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 818
  • Last login:May 22, 2023, 08:18:15 pm
Re: Need AHK script to run .bat file from key combination
« Reply #6 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.

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9226
  • Last login:June 13, 2024, 01:06:22 pm
  • ...
Re: Need AHK script to run .bat file from key combination
« Reply #7 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)
« Last Edit: December 11, 2012, 03:38:34 pm by BadMouth »

Le Chuck

  • Saint, make a poll!
  • Wiki Contributor
  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5509
  • Last login:June 06, 2024, 02:16:34 pm
  • <insert personal text here>
Re: Need AHK script to run .bat file from key combination
« Reply #8 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. 

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9226
  • Last login:June 13, 2024, 01:06:22 pm
  • ...
Re: Need AHK script to run .bat file from key combination
« Reply #9 on: December 01, 2012, 03:44:26 pm »
Here is a link to the Pololu AHK guide:
http://www.pololu.com/docs/0J45

You can download a pdf at the top.  It's only 8 pages.

griffindodd

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1514
  • Last login:June 29, 2023, 02:43:19 pm
  • Builds Stuff
Re: Need AHK script to run .bat file from key combination
« Reply #10 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.
I drink and I know things.

griffindodd

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1514
  • Last login:June 29, 2023, 02:43:19 pm
  • Builds Stuff
Re: Need AHK script to run .bat file from key combination
« Reply #11 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
« Last Edit: December 07, 2012, 12:01:43 am by griffindodd »
I drink and I know things.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5147
  • Last login:May 29, 2024, 07:09:08 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Need AHK script to run .bat file from key combination
« Reply #12 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.

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9226
  • Last login:June 13, 2024, 01:06:22 pm
  • ...
Re: Need AHK script to run .bat file from key combination
« Reply #13 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

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