Main > Software Forum

AHK2 help

(1/1)

DaOld Man:
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:
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: ---
#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
         }
       
    }
}


--- End code ---

Navigation

[0] Message Index

Go to full version