Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi there, quick strange question 🙂

Is it possible to have a certain key command "executed" by an event like descending through 500ft. AGL? 
(For instance, let's say I want to automatically save a screenshot for every of my approaches at 500 ft. AGL, so want my screenshot-key to be "pressed" automatically when I pass that altitude)

Thx,

Stu

 

Posted
11 hours ago, Stu Antonio said:

Is it possible to have a certain key command "executed" by an event like descending through 500ft. AGL? 
(For instance, let's say I want to automatically save a screenshot for every of my approaches at 500 ft. AGL, so want my screenshot-key to be "pressed" automatically when I pass that altitude)

Sure. You can have a lua script monitoring for events using event.intercept() on offset 0x0570, which is the plane altitude. In the handling function, you can read the ground altitude offset (either at 0x0200 or 0x0B4C, depending upon accuracy required) to determine the AGL. You can then test that value and do whatever you like - e.g. send keystrokes to the FS via offset 0x3200, or send controls to the FS via offset 0x3110.

John

Posted

Hi John, appreciate the quick response. Unfortunately I don't know how to program LUA scripts, I just thought there is a way to do this in FSUIPC.
No problem, I'll ask a friend who might be able to help me out based on your explanation above.

Thanks & regards,
Stu

Posted
18 minutes ago, Stu Antonio said:

 Unfortunately I don't know how to program LUA scripts, I just thought there is a way to do this in FSUIPC.

Lua scripts are the way to achieve such things in FSUIPC!

Check the User Contributions section - there may be something similar there that you can use or adapt for your use.

Also, event.intecept() is probably not the function you need, as this intercepts writes from 3rd party applications, not internal FSUIPC writes. You would need to use the event.offset() function on the plane altitude, offset 0200 or 0B4C.

Posted (edited)
4 hours ago, John Dowson said:

Also, event.intecept() is probably not the function you need, as this intercepts writes from 3rd party applications, not internal FSUIPC writes. You would need to use the event.offset() function on the plane altitude, offset 0200 or 0B4C.

Actually this is one case where using a timer event to do the AGL calculation at intervals (eg one a second should be enough) would be better, because otherwise you'll either get almost continuous events, or actually completely miss the trigger altitude if the ground is rising rather than the aircraft descending. So, something like

aglhigh = false

function checkAGL()
   ground = ipc.readSW(0x0B4C)
   altitude = ipc.readSW(0x0574)
   agl = (altitude - ground) * 3.142 -- convert to feet
   if agl > 550 then
      aglhigh = true
   elseif agl < 450 and aglhigh then
      aglhigh = false
      --SEND KEYSTROKE OR CONTROL HERE:
      -- ipc.keypress(keycode, shifts)
      -- ipc.control(control number)
   end
end

event.timer(1000, "checkAGL")

You'll need to fill in the action to be taken, where I've said. I've allowed 50 feet either side of 500 feet to avoid unnecessary repetitions with an uneven descent.

I've not tested this, but it should be okay.

Pete

Edited by John Dowson
space removed from 'else if'
Posted

Thanks for helping me out Pete, I used the above script to create "autorecord.lua" but couldn't get it to work properly. 

I tried to get it to "press" the V-key (for taking a screenshot on my system) by commenting out and adding the line ipc.keypress(K86).
But this did not to anything.

The log mentions an error, but I can't make sense of it:

********* LUA: "autorecord" Log [from FSUIPC version 6.1.2a] *********
    98328 System time = 09/08/2021 16:05:52, Simulator time = 17:00:08 (15:00Z)
    98328 LUA: beginning "C:\Users\Stu\Documents\Prepar3D v5 Add-ons\FSUIPC6\autorecord.lua"
    98328 *** LUA Error: C:\Users\Stu\Documents\Prepar3D v5 Add-ons\FSUIPC6\autorecord.lua:16: 'end' expected (to close 'function' at line 3) near '<eof>'
    98328 >>> Thread forced exit (ipc.exit or os.exit) <<<
    98328 System time = 09/08/2021 16:05:52, Simulator time = 17:00:08 (15:00Z)
********* LUA execution terminated: Log Closed *********

 

What am I missing? 

Thanks
Stu

Posted

It is giving you the error:
    *** LUA Error: C:\Users\Stu\Documents\Prepar3D v5 Add-ons\FSUIPC6\autorecord.lua:16: 'end' expected (to close 'function' at line 3) near '<eof>'

This is a problem in the script that Pete posted:

else if agl < 450 and aglhigh then

should be

elseif agl < 450 and aglhigh then

With the space, it expects another 'end'. I will correct.

  • Thanks 1
Posted
48 minutes ago, Pete Dowson said:

Also the key code for V is 86, not K86.

Pete

 

Okay, I see 🙂 I was just doing as this passage in the manual states "For key presses, the <key> value following the letter ‘K’ is the virtual key code for the key to be pressed." but maybe that's for something else...

Getting rid of the K worked perfectly, the script now does exactly what I wanted, that's so awesome!!

Thanks guys!!!

Cheers,
Stu

 

 

Posted
4 minutes ago, Stu Antonio said:

Okay, I see 🙂 I was just doing as this passage in the manual states "For key presses, the <key> value following the letter ‘K’ is the virtual key code for the key to be pressed." but maybe that's for something else...

No, that for this - it does say to use the key code following (or after may be better) the letter 'K'.

 

Posted
13 minutes ago, Stu Antonio said:

I was just doing as this passage in the manual states "For key presses, the <key> value following the letter ‘K’ is the virtual key code for the key to be pressed." but maybe that's for something else...

Assignments in the FSUIPC INI file can be to Key presses or Controls. To differentiate between those they are preceded (not followed by) a K or a C.

But that is nothing to do with the Lua library functions like ipc.keypress and ipc.control, where the parameters are numbers and there's no danger of confusion in any case.

Glad it is working for you.

Pete

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.