Jump to content

Autohotkey and DCS


Recommended Posts

Hi all,

 

I tried posting this message under another category, but someone suggested I post it here, so that's what I'm doing.

 

For those of you familiar with autohotkey, perhaps you can help me out.

 

I'm setting up an autohotkey sequence to press and release a series of keys. Here's the beginning of the script (the full script is much longer, but essentially involves more of the same).

 

`::

Send {1 down}

Sleep 500

Send {1 up}

Sleep 500

Send {2 down}

Sleep 500

Send {2 up}

Sleep 500

Send {3 down}

Sleep 500

Send {3 up}

 

When the ` is pressed in any document, it works fine, giving 1, 2, then 3. But when the ` key is pressed while in DCS (in the A10C), nothing happens. If I press 1, 2, and 3, the functions associated with pressing them take place normally (I've tried varying the functions, but it doesn't really matter what they are, there's no response).

 

Any suggestions?

Link to comment
Share on other sites

I'm not an expert, but heres the code I'm using, example below is for RALT P:

 

 

newTiming := 350

 

>!P::

Send {Blind}{ralt down}{p down}

sleep, newTiming

Send {Blind}{ralt up}{p up}

return

 

Not 100% sure of the syntax for ' have you tried if it works with a difference letter?

Hornet, Super Carrier, Warthog & (II), Mustang, Spitfire, Albatross, Sabre, Combined Arms, FC3, Nevada, Gulf, Normandy, Syria AH-6J

i9 10900K @ 5.0GHz, Gigabyte Z490 Vision G, Cooler Master ML120L, Gigabyte RTX3080 OC Gaming 10Gb, 64GB RAM, Reverb G2 @ 2480x2428, TM Warthog, Saitek pedals & throttle, DIY collective, TrackIR4, Cougar MFDs, vx3276-2k

Combat Wombat's Airfield & Enroute Maps and Planning Tools

 

cw1.png

Link to comment
Share on other sites

I'm not an expert, but heres the code I'm using, example below is for RALT P:

 

 

newTiming := 350

 

>!P::

Send {Blind}{ralt down}{p down}

sleep, newTiming

Send {Blind}{ralt up}{p up}

return

 

Not 100% sure of the syntax for ' have you tried if it works with a difference letter?

Thanks for the reply. I tried using your syntax with different letters and functions and nothing worked while in DCS (worked fine outside of it though). I think there's something weird going on with my system, since other people seem to use autohotkey scripts just fine.

Link to comment
Share on other sites

Try to run the script and/or DCS as admin (both at the same level). Also do you have anything else in your script? If so please show us.

 

I remember DCS couldn't see Roccat Power Grid output until it was running as Admin.

Link to comment
Share on other sites

Also depends what you are trying to do, I discovered recently that different DCS elements have different key delays, I moved to a programmable POS keyboard for the Hornet and found that while its default keypress worked for some buttons like on the IFEI for other areas like the UFC it needed a longer keypress to register. so I had to move to a AutoHotkey script, but in notepad or even DCS config it registered fine. I would have thought 500 was long enough to catch most things though.

Hornet, Super Carrier, Warthog & (II), Mustang, Spitfire, Albatross, Sabre, Combined Arms, FC3, Nevada, Gulf, Normandy, Syria AH-6J

i9 10900K @ 5.0GHz, Gigabyte Z490 Vision G, Cooler Master ML120L, Gigabyte RTX3080 OC Gaming 10Gb, 64GB RAM, Reverb G2 @ 2480x2428, TM Warthog, Saitek pedals & throttle, DIY collective, TrackIR4, Cougar MFDs, vx3276-2k

Combat Wombat's Airfield & Enroute Maps and Planning Tools

 

cw1.png

Link to comment
Share on other sites

Antoine,

 

Could you let me know how to run Autohotkey and DCS in administrator mode (I use DCS through Steam)? Also, is there a way to verify it's working? I right-clicked on the Autohotkey icon and clicked run as administrator, but it simply started the program.

 

Thanks.

Link to comment
Share on other sites

Antoine,

 

Could you let me know how to run Autohotkey and DCS in administrator mode (I use DCS through Steam)? Also, is there a way to verify it's working? I right-clicked on the Autohotkey icon and clicked run as administrator, but it simply started the program.

 

Thanks.

 

I run steam as Admin, so I think it run all game as admin after that. To run an AHK script as admin you just have to right click on the script file and click "run as admin". I don't know how to check if "working". It should indeed just start.

 

But for exemple if the game is running as admin and not the AHK script, then the game might not care about what the ahk script is trying to say. By running the ahk script at the same level of privilege you could solve the issue.


Edited by Ant0ine
Link to comment
Share on other sites

  • 4 months later...

Not to start a new thread... My ahk script outputs both key presses and mouse wheel up/down. Running AutoHotkey as admin, only key presses get through to DCS. Mouse scrolls in all other apps fine. ONE time I managed to get it to work inside DCS (to turn dials) without changing the script or anything I can think of, but never since. Running DCS not as admin does not make a difference.

 

I think DCS processes keyboard and mouse interrupts on some low level, because F5 is always recognized, even though I replaced it with RWin-F5 in ahk and TARGET's Event Viewer sees it so. Also, key presses in DCS repeat faster than 500 ms delay system-wide (i.e. outside view zoom).

 

Any insight on how to consistently turn mouse wheel in DCS from an ahk script? I don't want to change my TARGET profile into a script just for that purpose...

12900KF@5.4, 32GB DDR4@4000cl14g1, 4090, M.2, W10 Pro, Warthog HOTAS, ButtKicker, Reverb G2/OpenXR

Link to comment
Share on other sites

Not to start a new thread... My ahk script outputs both key presses and mouse wheel up/down. Running AutoHotkey as admin, only key presses get through to DCS. Mouse scrolls in all other apps fine. ONE time I managed to get it to work inside DCS (to turn dials) without changing the script or anything I can think of, but never since. Running DCS not as admin does not make a difference.

 

I think DCS processes keyboard and mouse interrupts on some low level, because F5 is always recognized, even though I replaced it with RWin-F5 in ahk and TARGET's Event Viewer sees it so. Also, key presses in DCS repeat faster than 500 ms delay system-wide (i.e. outside view zoom).

 

Any insight on how to consistently turn mouse wheel in DCS from an ahk script? I don't want to change my TARGET profile into a script just for that purpose...

 

Try this (adapted from above -- it really gives AHK scripts a lot more consistency using it in all cases):

 

send, {blind}{wheeldown down}

sleep, 25

send, {blind}{wheeldown up}

 

Worked for me in quick testing. For things like the UFC buttons you might need to push the sleep value up to 500 because they seem to need a longer press. Play with the number until you get the length you want.

This should also work if you want to add RWin-F5 (not sure if you were having issues getting that to work or not:

 

send, {blind}{rwin down}{f5 down}

sleep, 25

send, {blind}{rwin up}{f5 up}

 

My experience was that I could get the left versions (i.e. LALT, LSHIFT) to work using !, + etc, but not the right versions. Using the above code instead it all works.

Link to comment
Share on other sites

Hello Rob, thanks for replying! Unfortunately, changing the code did not make a difference. I tried send, sendplay, sendinput with different delay values. I think blind is irrelevant, but I added it as per your suggestion. Currently, the code looks like this:

 

NumpadDiv::

{

sendplay, {blind}{wheelup down}

sleep, 250

sendplay, {blind}{wheelup up}

}

return

 

NumpadMult::

{

sendplay, {blind}{wheeldown down}

sleep, 250

sendplay, {blind}{wheeldown up}

}

return

 

I fly in VR. The Idea is to zoom in-out in external views and to turn dials in the cockpit then the mouse is hovering over. Maybe you could test it? It does not make a difference if I keep Num/ and Num* bound to slow zoom, or clear them.

 

About the KP5 (sorry I called it F5 in the message above), my UFC is pressed fine (waits until I release the key), but the VR view gets recentered. The piece of code is as follows:

 

;For some reason NumpadClear is not k-hook and have to use *

*NumpadClear::

SendInput, {RWin Down}

Sleep, 1

SendInput, {Numpad5 Down}

Sleep, 1

KeyWait NumpadClear

Sleep, 1

SendInput, {Numpad5 Up}

Sleep, 1

SendInput, {RWin Up}

return

 

12900KF@5.4, 32GB DDR4@4000cl14g1, 4090, M.2, W10 Pro, Warthog HOTAS, ButtKicker, Reverb G2/OpenXR

Link to comment
Share on other sites

I couldn't get response with sendplay, only with send. I use the line "sendmode input" at the top of the file rather than specifying in each line (although, even commenting that out doesn't change reaction with this code). Have you tried it outside of DCS (i.e. in a browser or something) to make sure it works? If it works there try it in DCS in 2D. If it works there I'd guess maybe it's something with VR that AHK doesn't see the mouse cursor focus as being on the knob you're trying to turn (but that's completely a guess on my part). I don't have VR so I can't test it on that unfortunately. Not sure what else to suggest :(.

And honestly, I don't know if the {blind} part matters (it was in the original so I left it in -- haven't been bothered to dig into it and see what it's supposed to do :blush:)

Link to comment
Share on other sites

OK, one last hail Mary pass: does your actual mouse wheel button work in DCS? Just wondering if it's bound in the UI layer or General layer which block other binds. Then I would suggest/ask if you can get any other combo's to work in DCS -- i.e. set the "K" key to "M" or whatever you have bound to master arm or something easy to see and/or set the NumpadMult to "M" rather than wheeldown to see if that works. The other thing that occurred to me while thinking of that is to just check that NumpadMult and Div aren't bound in either of these layers as that might be overriding them working (and if you happen to have one of the addon GPS modules I think they can cause issues too).

Very frustrating that it's not working for you :(.

Link to comment
Share on other sites

Thanks for caring! Mouse wheel is not bound anywhere in DCS, it just works. Sure I can turn the dials with my actual mouse and trackpad. Other keys are sent no problem. NumpadMult and Div are indeed bound by default to zoom in and out in UI Layer, General and for each aircraft, but deleting those bindings had no effect on mouse wheel not working.

 

Autohotkey should hide the original keystrokes and replace them with new events, but it does not happen with DCS. It receives both KP5 and RWin KP5, for example, thus pressing the UFC button 5 and recentering the view. Other programs on my PC do receive only final events, and mouse wheel works there. That is why I think DCS processes keyboard and mouse interruptions on some lower level.

 

If the script turns dials for you, is it on Stable or OB?

 

I found another potential solution. I can bind wheel up and down to keyboard on UI Layer. The only problem, each keypress turns it by a small amount. Is it possible to repeat send down+up events in a loop while the original key is held?

12900KF@5.4, 32GB DDR4@4000cl14g1, 4090, M.2, W10 Pro, Warthog HOTAS, ButtKicker, Reverb G2/OpenXR

Link to comment
Share on other sites

...That is why I think DCS processes keyboard and mouse interruptions on some lower level...

 

Agree with this. I use AH to remap the stupid App key on my otherwise decent keyboard to R-Win. It works in absolutely everything except DCS which still sees it as the App key.

 

 

CPU:5600X | GPU:RTX2080 | RAM:32GB | Disk:860EVOm.2

Link to comment
Share on other sites

  • 1 year later...

Having the same problem, I don't think it's the script itself I think it's the hotkey press not making it out of DCS to trigger the macro in AutoHotKey. I found a work around but don't understand why it works. Make a second copy of your script and rename it "whatever 2". Then start script "whatever" and then "whatever 2" so they are both running at the same time. Now go into DCS and your hotkey will activate the script. It's not elegant but it works, now to find out why. My guess is DCS is blocking the first script, by process name probably, but when the script is run again under a second name DCS ignores it and does not block it for whatever reason. I use this for my radar/weapon setup because ED still hasn't released a data cartridge which is mind boggling, how long has this been a fundamental necessity? I mean the JF-17 developers had to create one for their module themselves yet the official ED planes don't have the feature? Come on man.


Edited by rfxcasey
  • Like 1
Link to comment
Share on other sites

On 6/19/2020 at 3:56 PM, Mudfly said:

Hi all,

 

I tried posting this message under another category, but someone suggested I post it here, so that's what I'm doing.

 

For those of you familiar with autohotkey, perhaps you can help me out.

 

I'm setting up an autohotkey sequence to press and release a series of keys. Here's the beginning of the script (the full script is much longer, but essentially involves more of the same).

 

`::

Send {1 down}

Sleep 500

Send {1 up}

Sleep 500

Send {2 down}

Sleep 500

Send {2 up}

Sleep 500

Send {3 down}

Sleep 500

Send {3 up}

 

When the ` is pressed in any document, it works fine, giving 1, 2, then 3. But when the ` key is pressed while in DCS (in the A10C), nothing happens. If I press 1, 2, and 3, the functions associated with pressing them take place normally (I've tried varying the functions, but it doesn't really matter what they are, there's no response).

 

Any suggestions?

Having the same problem, I don't think it's the script itself I think it's the hotkey press not making it out of DCS to trigger the macro in AutoHotKey. I found a work around but don't understand why it works. Make a second copy of your script and rename it "whatever 2". Then start script "whatever" and then "whatever 2" so they are both running at the same time. Now go into DCS and your hotkey will activate the script. It's not elegant but it works, now to find out why. My guess is DCS is blocking or intercepting the first script, by process name or on the keyboard code level, but when the script is run again under a second name DCS ignores it and does not block or intercept it for whatever reason.

Now here is the strange part. I use Opentrack for head tracking which I run in the background while DCS is running. I have the 'num 5' key set in Opentrack to re-center my head tracker. This works fine, every time, and the key bind makes it out of DCS when in game to trigger a re-center head tracking action in Opentrack. On a side note, if DCS is running as admin 'num 5' will not make it out to trigger re-centering in Opentrack so both DCS and Opentrack are running on the regular permission level and it works fine. I'd like to know the mechanism behind the keystroke making it to Opentrack, It might be an issue where AutoHotKey's hotkey is working on a directX direct input level where Opentrack isn't, but I don't know how to examine the traffic, maybe Wireshark might be able to capture what's happening.

I've read the suggestion that VoiceAttack works on both the Voice and key triggering level, but I cannot confirm this as I don't have the software. Apparently VoiceAttack can trigger macros and actions via voice input but keyboard input as well more like a traditional macro program. I might have to buy it and check it out myself.

Let me say, to my understanding, Opentrack uses the same protocol to communicate with DCS as Naturalpoint's Track IR, so there is, at least for Track IR, built in code for working with DCS natively. That being the case, I'm wondering if ED has a deal or agreement with VoiceAttack that allows their software to also interface with DCS but attempt to block other programs from performing the same functionality in favor of promoting the use of a partners solution, but I digress.

I wrote a simple batch file to start the two scripts, which are named differently but contain the same code, simultaneously. Once again, not the ideal solution but it works. Just for giggles, I'm going to run an empty script or one only containing the hotkey function to run side by side with one copy of the actual script containing the macro code and see if it still works, I'm guessing it will.

I use this for my radar/weapon setup because ED still hasn't released a data cartridge which is mind boggling, how long has this been a fundamental necessity? I mean the JF-17 developers had to create one for their module themselves yet the official ED planes don't have the feature?


Edited by rfxcasey
Link to comment
Share on other sites

  • 2 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...