Stu Antonio Posted August 8, 2021 Report Share Posted August 8, 2021 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 Ā Link to comment Share on other sites More sharing options...
John Dowson Posted August 9, 2021 Report Share Posted August 9, 2021 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 Link to comment Share on other sites More sharing options...
Stu Antonio Posted August 9, 2021 Author Report Share Posted August 9, 2021 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 Link to comment Share on other sites More sharing options...
John Dowson Posted August 9, 2021 Report Share Posted August 9, 2021 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. Link to comment Share on other sites More sharing options...
Stu Antonio Posted August 9, 2021 Author Report Share Posted August 9, 2021 9 minutes ago, John Dowson said: Check the User Contributions section Will do, thanks! Ā Link to comment Share on other sites More sharing options...
Pete Dowson Posted August 9, 2021 Report Share Posted August 9, 2021 (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 August 9, 2021 by John Dowson space removed from 'else if' Link to comment Share on other sites More sharing options...
Stu Antonio Posted August 9, 2021 Author Report Share Posted August 9, 2021 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 Link to comment Share on other sites More sharing options...
John Dowson Posted August 9, 2021 Report Share Posted August 9, 2021 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. 1 Link to comment Share on other sites More sharing options...
Pete Dowson Posted August 9, 2021 Report Share Posted August 9, 2021 Also the key code for V is 86, not K86. Pete Ā 1 Link to comment Share on other sites More sharing options...
Stu Antonio Posted August 9, 2021 Author Report Share Posted August 9, 2021 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 Ā Ā Link to comment Share on other sites More sharing options...
John Dowson Posted August 9, 2021 Report Share Posted August 9, 2021 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'. Ā Link to comment Share on other sites More sharing options...
Pete Dowson Posted August 9, 2021 Report Share Posted August 9, 2021 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 Ā Ā Link to comment Share on other sites More sharing options...
Stu Antonio Posted August 9, 2021 Author Report Share Posted August 9, 2021 Understood. Thanks!Ā š Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now