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: AHK2 help  (Read 1429 times)

0 Members and 1 Guest are viewing this topic.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5180
  • Last login:Today at 11:45:21 am
  • Wheres my coffee?
    • Skenny's Outpost
AHK2 help
« on: February 12, 2026, 11:10:48 pm »
Im trying to run a AHK V2 script in Windows 10.
I load it when PC starts.
When the script detects both left and right key pressed, it sends Escape to exit mala screensaver, or any game being run.
I then send a V to exit Mala.
It then exits Mala, then shutdowns the PC.
All seems to work fine except the Send Esc.
If Im not playing a game, Mala quits and then I get a clean shutdown.
However If I am running a game, when ESC is sent, the game doesnt exit.
It goes straight into PC shutdown.
I have tried
send {Esc}
and
send "{Esc}"
in the script, and neither seems to work.
Im sure its something simple, I have exhausted searching the net for it.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5180
  • Last login:Today at 11:45:21 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: AHK2 help
« Reply #1 on: Yesterday at 05:17:23 pm »
Still having problems.
This works on every emulator I have except mame.
It is watching for both left and right keys being pressed and held.
It should send esc, to exit the emulator, or screen saver if its on, then V to exit mala.
I use V to exit mala so I can go into the PC from the keyboard, if needed.
When I run it within mame, it does not exit mame, but it does shutdown after all the delays.
Mala does not get updated. (Selected emulator and game to display on next run).
im sure it has something to do with mame taking the focus?
id appreciate any help.

Code: [Select]

#SingleInstance Force  ;If this script is already running, do not restart it

k1name := "left"      ;  key 1
k2name := "right"     ;  key 2

loop
{
    sleep 1500   ;  milliseconds sleep to reduce CPU usage
    k1 := getkeystate(k1name, "P")     ; get key 1 state getkeystate(k1name, "P")
    k2 := getkeystate(k2name, "P")     ; get key 2 state

    {
        if ( k1 & k2 & !trig )
       {
            trig := 1       ; set flag to avoid repetition
            SetKeyDelay 500
            Send, {Esc}
            Sleep 750
            SetKeyDelay 250
            Send, {v}
            Sleep 5000 ;Pause to allow mala to close
            ;put in windows ahutdown here.     
            Shutdown 12
       
            ;A combination (sum) of the following numbers:
            ;0 = Logoff
            ;1 = Shutdown
            ;2 = Reboot
            ;4 = Force
            ;8 = Power down
       
            ;Add the required values together.   
        }
        if ( !k1 & !k2 )  ;( !k1 || !k2 )
         {
           trig := 0
         }
       
    }
}