Using AHK to send commands

Interested in building your own home grown cockpit?

Moderators: Uros, OXO

Post Reply
Allen
Posts: 42
Joined: Tue Dec 04, 2018 10:42 pm

Using AHK to send commands

Post by Allen » Tue Jan 29, 2019 3:57 pm

To anyone who can help please,

I am setting up a new simulator, and intending to use 'touch screens' in the cockpit to display the instruments from simPlugins, with part of the touch screen space made available for buttons programmed using Auto Hot Keys, and projectors for the main view of Condor. These buttons are intended to duplicate the keyboard functions such as 'Pause' (key 'p') 'Thermal Helpers' (key 'h') etc. so that it will be unnecessary to have a keyboard or pad in the cockpit.
I have been able to program a button with AHK to send a 'p' to 'Notepad' or any other program, even when it does not have the 'focus', but have not been successful with sending the keystroke to Condor when it is running.
The basic AHK script is:

Gui, Add, Button, x16 y7 w80 h30, Pause
Gui, Show, x366 y234 h49 w200, Pause Condor
Return
ButtonPause:
IfWinExist, ahk_class Condor.exe
{
WinActivate ; Automatically uses the window found above.
WinMaximize ; same
Send p
return
}
Send p
GuiClose:
ExitApp

Does anyone have experience of using AHK and can possibly guide me in the right direction?

I would be very grateful of any help,

Many thanks,

Allen

User avatar
wickid
Posts: 2429
Joined: Mon Dec 04, 2006 7:32 pm
Location: Venlo, NL
Contact:

Re: Using AHK to send commands

Post by wickid » Tue Jan 29, 2019 3:59 pm

I have working programs. Sent me a PM how I can contact you
PH-1504, KOE

User avatar
wickid
Posts: 2429
Joined: Mon Dec 04, 2006 7:32 pm
Location: Venlo, NL
Contact:

Re: Using AHK to send commands

Post by wickid » Tue Jan 29, 2019 5:14 pm

For those interested. This code works:

Code: Select all

Gui, Add, Button, x16 y7 w80 h30, Pause
Gui, Show, x366 y234 h49 w200, Pause Condor
Return
ButtonPause:
IfWinExist,  Condor version 2.0.5
{
WinActivate
Send p
return
}
Send p
GuiClose:
ExitApp
This allows you to operate the pause fuction in condor from a button on a touchscreen.
PH-1504, KOE

Allen
Posts: 42
Joined: Tue Dec 04, 2018 10:42 pm

Re: Using AHK to send commands

Post by Allen » Tue Jan 29, 2019 8:17 pm

Hi Wickid,

I have tried your AHK script, but still cannot get it to work - and I've tried in all three 'windowed' options for Condor. I have even tried without a touch screen, just using the 'Windowed' option so that I can see (and mouse-click) on the AHK 'Pause' button.

It seems such a simple thing to achieve - but is proving to be rather difficult!

Just a thought - should I be using the 32 bit AHK compiler as Condor is still 32 bit, even though I am using a 64 bit version of Windows?

I appreciate your help,

Best wishes,

Allen

User avatar
wickid
Posts: 2429
Joined: Mon Dec 04, 2006 7:32 pm
Location: Venlo, NL
Contact:

Re: Using AHK to send commands

Post by wickid » Tue Jan 29, 2019 8:25 pm

Strange, for me it works. Sometimes it take a bit of time after the click before the sim pauses. I'm in Full screen emulation. I have to alt tab to the window with the pause button because the mouse doesn't work when condor has focus. I guess on your touchscreen you have to double tap the pause button.

You don't have to compile the .exe for testing. You can launch an autohotkey script in it's raw form as well.
PH-1504, KOE

Allen
Posts: 42
Joined: Tue Dec 04, 2018 10:42 pm

Re: Using AHK to send commands

Post by Allen » Tue Jan 29, 2019 8:34 pm

Hi Wickid,

Yes - I'm having a little more success - using the alt-tab to get the focus on the button, and then back to Condor.
As you say, it is a little slow to respond.

I'll carry on with a bit more testing, and then try the touch screen.

Thanks for your help,

Allen

Allen
Posts: 42
Joined: Tue Dec 04, 2018 10:42 pm

Re: Using AHK to send commands

Post by Allen » Tue Jan 29, 2019 8:51 pm

Hi Wickid,

I have found that adding:

Gui, Add, Button, x16 y7 w80 h30, Pause
Gui, Show, x366 y234 h49 w200, Pause Condor
Return
ButtonPause:
IfWinExist, Condor version 2.0.5
{
WinActivate
Send p
return
}
Send p
ControlFocus, , Condor version 2.0.5 : THIS LINE
GuiClose:
ExitApp

It has become a bit more responsive.

Still to try the touch screen..

Best wishes,

Allen

Allen
Posts: 42
Joined: Tue Dec 04, 2018 10:42 pm

Re: Using AHK to send commands

Post by Allen » Tue Jan 29, 2019 10:49 pm

Anyone who is interested,

After several hours testing, I have been unable to get AHK to be responsive enough for use in sending keys to 'Condor' when it is running. I have tried using 'P' for the 'Pause' function as well as 'H' for the thermal helpers. I have also tried all the combinations of the AHK 'Send' commands. There can be a wait of up to 15 seconds before 'Condor' responds to the sending of the 'P' or 'H' - sometimes it is as little as 2 seconds , which would be acceptable if it were consistent.
This is using both the 'ALT TAB' method to switch to the AHK window, and then pressing 'Enter', and also using a touch screen

Does anyone have any other solution?

Many thanks,

Allen

User avatar
wickid
Posts: 2429
Joined: Mon Dec 04, 2006 7:32 pm
Location: Venlo, NL
Contact:

Re: Using AHK to send commands

Post by wickid » Tue Jan 29, 2019 11:11 pm

I use something like this:

Image

Connected via a POkeys 54U I/O board
PH-1504, KOE

Post Reply