Jump to content
The simFlight Network Forums

LAU script to emulate key presses


Recommended Posts

My view perspective (eye point) is too high in the cockpit on approach. Can I write a lua script to move my seat lower (shift - backspace) by a given number. I can do this manually but once I know how much my seat needs lowering it will be much quicker than doing it manually.

 

By the way I dont have to cockpit showing so it will be the outside view perspective that changes.

 

Any help will be appreciated.

 

Graham

Link to comment
Share on other sites

My view perspective (eye point) is too high in the cockpit on approach. Can I write a lua script to move my seat lower (shift - backspace) by a given number. I can do this manually but once I know how much my seat needs lowering it will be much quicker than doing it manually.

 

By the way I dont have to cockpit showing so it will be the outside view perspective that changes.

 

Any help will be appreciated.

 

Graham

 

You don't need a Lua plug-in to do that, only a button or keypress assigned which has the right number of such keypresses programmed. Just program once in the FSUIPC options, then edit the INI file to replicate the resulting line with subsequent line numbers.

 

It would be better (more efficient) to assign the actual FS control directly rather than the keypress which FS translates into a control. If you don't know what it is just enable FSUIPC event logging and the log will show the name when you use it.

 

Anyway, if you just need a permanent change in the view, doesn't this get saved when you save a flight, so it is reinstated when you next load?

 

Regards

Pete

Link to comment
Share on other sites

A LUA method would have been grand. I only need seat down during landing and up for flight. I was thinking of incorporating it into undercarriage up and down selections. Im sure there will be an offset for seat up and down. Just need to find it.

Graham

Link to comment
Share on other sites

A LUA method would have been grand.

 

Not sure why you'd opt for something more complex over something which would do the same job more simply.

 

In any case you'd not "emulate key presses" as implied in your title, but simply send the appropriate control numbers, from the list installed in your FSUIPC Documents folder.

 

I only need seat down during landing and up for flight. I was thinking of incorporating it into undercarriage up and down selections.

 

Again, just another control assigned in a multiple assignment or in a macro.

 

Im sure there will be an offset for seat up and down. Just need to find it.

 

No, there are no offsets for the "eyepoint", which is what you are talking about. You have to use eyepoint controls -- EYEPOINT UP and EYEPOINT DOWN, in fact. You can send them from a Lua plug-in, of ocurse, but that's just a more long-winded way of doing via a straight multi-entry button or key assignment or a macro.

 

Regards

Pete

Link to comment
Share on other sites

Ive tried using

 

ipc.keypress(17,16,81)

 

to send "ctrl shift q" to fsx but it doesnt seem to work

 

Is the syntax wrong ?

 

Yes, it is wrong. You could actually look in the FSUIPC4 log file where it would tell you so. That's where errors will be announced!

 

What is the correct syntax if it is

 

You need to refer to the FSUIPC Lua Library document for Lua library function syntax. I would need to look things up too (I don't remember everything!), so really it would be quicker for you to actually use the documentation yourself. It is in your FSUIPC Documents folder, as you were informed in the FSUIPC "Installing and Registering" Guide.

 

Once you get used to looking things up in the documentation it will a lot quicker for you too, with other similar queries.

 

Regards

Pete

Link to comment
Share on other sites

Yes been there and read that before i posted. Thats where my attempt came from. Its the triple key thats confusing things. I think im going to assign a single spare key to the tilt up viewpoint and just call that with a LUA script.

Thanks

Graham

Link to comment
Share on other sites

Yes been there and read that before i posted. Thats where my attempt came from. Its the triple key thats confusing things

 

There is NO [art of any of my documents which shows three parameters for KeyPress. There are one (for a normal key) or two parameters when you want to add shift actions like Control, Alt, Shift, Tab, Windows and Menu keys. The shift codes are simply added together. It is dead simple. i really don't understand what the fuss is about. If you read something and don't understand it, ask the question and I'll explain. but you have to look things up yourself and not invent your own formats.

 

I think im going to assign a single spare key to the tilt up viewpoint and just call that with a LUA script.

 

I find it absolutely baffling that you don't understand simple keycode values yet want to do over-complex things like use Lua when a simple direct keypress assignment would do. It's really weird.

 

Pete

Link to comment
Share on other sites

I belive using capital letters is shouting. There really is no need to shout Pete. I come here cap-in-hand asking for help. I'm not a computer programmer for all you know I could even be mentally challenged so why you have no patience with me and many others is as baffling to me as some of my questions are to you.

Quote "f you read something and don't understand it, ask the question and I'll explain. but you have to look things up yourself and not invent your own formats." - I did ask ! That's why I'm here.

I've tried reading the manual as you've asked me to in the past and I find it all hard to understand. That's not a crime but just as far as my understanding in this subject stretches. I appologise for being mentally inadequate. My job is teaching aerospace engineering and fault diagnosing aircraft faults. If I gave you a manual covering that subject Pete and asked you to get on with it you would struggle. There's no manual that can teach experience which is what you have and therefore why we come cap in hand and ask for your help. I want to use lau because moving my viewpoint chin up will be incorprated with my uc down selection. My uc up selection will cancel autobrake, select uc off ( which I've already achieved ) and then reset the viewpoint. Its only my approach perspective I'm not happy with. I hope that clears that up a bit.

Thanks

Graham

Link to comment
Share on other sites

Are you using FSX? If so, you may alternatively fiddle with the "Camera Configuration" and "Camera HotKeySelect" setting instead.

Make a new camera definition in the aircraft.cfg, adjust its variables to your liking ( ie, "InitialXyz", "InitialPbh", "InitialZoom") then set its "HotKeySelect" key ( #5-10 available, defaults are 1-4) so you can assign a keypress or joystick button to activate this custom view anytime you wish.

 

example.

[CameraDefinition.XXX]
Title = Cockpit - Landing POV
Guid = {10EB1B1C-FFAA-44cf-9E23-DE622E32C70C}
Description = 2D Cockpit view for approach/landing sequence.
Origin = Cockpit
ShowPanel = YES
SnapPbhAdjust = Ordinal
SnapPbhReturn = TRUE
PanPbhAdjust = Ordinal
PanPbhReturn = TRUE
Track = None
ShowAxis = FrontOnly
AllowZoom = TRUE
InitialZoom = 0.60
SmoothZoomTime = 1.0
ShowWeather = YES
ShowLensFlare = FALSE
XyzAdjust = TRUE
InitialXyz = 0,6,-40
InitialPbh = 12,0,0
Category = Cockpit
CycleHidden = YES
HotKeySelect = 8

To make this custom view available globally (applies for any aircrafts), add/modify the camera definition in camera.cfg (%APPDATA%\Microsoft\FSX\Camera.CFG).

 

 

I only need seat down during landing and up for flight. I was thinking of incorporating it into undercarriage up and down selections.

 

For automatic switching of these views/cameras triggered by undercarriage up/down, try this simple LUA script,

-- init landing pov
ldgpov = 0

function gearstat(offset, val)
    if val ~= 0 and ldgpov == 0 then
      ipc.control(66858)
      ldgpov = 1
    else
      ipc.control(66851)
      ldgpov = 0
    end    
   ipc.sleep(1000)
end

event.offset(0x0BE8, "UW", "gearstat")

or, optionally by using an XML gauge :

<?xml version="1.0" encoding="utf-8"?>
<Gauge Name="Landing POV" Version="1.0">

    <Comment>
        Automatic view-switching. Triggered by landing gear toggle.
        Change the "VIEW_CAMERA_SELECT_#" in the macro section below that suits to your aircraft's camera definition.
    </Comment>

    <Macro Name="NORM_View">(>K:VIEW_CAMERA_SELECT_1)</Macro>
    <Macro Name="LNDG_View">(>K:VIEW_CAMERA_SELECT_8)</Macro>

    <Update Hidden="Yes" Frequency="1"/>

        <Keys>
            <On Event="GEAR_TOGGLE">
                (L:LandingPOV) ! (A:GEAR HANDLE POSITION,percent) 50 > && if{ @LNDG_View 1 (>L:LandingPOV) }
                (L:LandingPOV) (A:GEAR HANDLE POSITION,percent) 50 < && if{ @NORM_View 0 (>L:LandingPOV) } ||
            </On>
        </Keys>

</Gauge>

Make a new folder named "custom" in main FSX "Gauges" folder.

Copy and paste the XML code above into a new text document inside this "custom" folder, then rename it as "landing_pov.xml".

Edit your aircraft's PANEL.CFG, append the following code into its [Window00] and [Vcockpit01] section :

gauge99=custom!landing_pov, 0,0,1,1

I hope this method works on your setup. I haven't check all those script aboves thoroughly, just made some modification from my custom Sling/Hoist viewports I've applied on helis.

Regards,

-xcorez-
HC006XC

Edited by xcorez
Link to comment
Share on other sites

Ive tried a lau script

ipc.control(66151) -- would tie this into UC down selection

This tilts the head up which is the effect Im after

Then assigning

ipc.control(66147) -- which resets the view after this incorporated into uc up

The trouble is the 66151 control needs to be held for a few seconds for the view to slew up but I cant see a way to do this.Your camera config looks very complicated to a novice like myself and would probably just bog me down further but I am grateful for your suggestion and code example xcorez. If I could get the 66151 to work for me I could trigger it using your UC position detection routine.

Graham

Thank you very much for that in depth reply. That must have taken you quite a while to do :-)

Link to comment
Share on other sites

I belive using capital letters is shouting. There really is no need to shout Pete.

 

Shouting? Which part? Do you mean the "NO" where it is merely emphasis. I was just too lazy to make it italisized. Sorry.

 

I come here cap-in-hand asking for help. I'm not a computer programmer for all you know I could even be mentally challenged so why you have no patience with me and many others is as baffling to me as some of my questions are to you.

 

 

If you are no programmer why are you so intent on making your simple needs into a Lua plug-in. Lua is a programming language. Why not simply use the assignment facilties as I keep begging you to do? You seem to want to baffle yourself, and I am trying to pull you back.

 

Quote "f you read something and don't understand it, ask the question and I'll explain. but you have to look things up yourself and not invent your own formats." - I did ask ! That's why I'm here.

 

I can't see how you looked up the KeyPress function which explicity showed one or two parameters with explanations, yet you tried something with 3 parameters not following the stated requirements at all. If you didn't understand what you read why not ask about it instead of making up your own versions? I can expand upon things you don't understand, but not once have you said what it is you don't understand. You simply want to forge ahead down a path I keep advising against.

 

I've tried reading the manual as you've asked me to in the past and I find it all hard to understand. That's not a crime ...

 

Agreed. So why not ask questions about it?

 

I want to use lau

 

 

Lua, not Lau. Sorry to correct you -- originally I thought it was a typo but I see you are consistent.

 

because moving my viewpoint chin up will be incorprated with my uc down selection. My uc up selection will cancel autobrake, select uc off ( which I've already achieved ) and then reset the viewpoint. Its only my approach perspective I'm not happy with. I hope that clears that up a bit.

 

 

Even then, such sequences suite multiple assignment or macros better. after all it sounds like a simple list of controls to be sent. Programming (which is what Lua is all about) can include decision making, lops, and other clever things, evidently not needed for this.

 

Pete

Link to comment
Share on other sites

The trouble is the 66151 control needs to be held for a few seconds for the view to slew up

 

Are you sure this is not simply the repetition, just a single use hardly making any difference? With keyboard use you'll get the keyboard repetition rate.  Multiple assignment of the control to a button would do the job.

 

Try using the Event logging in FSUIPC to see what happens when you get the result you want, and simply emulate that. If you run FSX in Windowed mode, temporarily, you can enable FSUIPC's console log and see the resluts in real time on screen.

 

Pete

Link to comment
Share on other sites

Your camera config looks very complicated to a novice like myself and would probably just bog me down further

 

Graham, I found this Microsoft ESP online documentation about "Camera Configuration" does work for customizing FSX camera definition, and there's also an article in FSDeveloper Wiki about "Camera Views - Changing" about using saved flight .FLT camera definition for further tweaking your aircraft's camera definition.

 

Once you have tweaked a customized camera definition for desired perspective/POV, it will be more easier to incorporate it into your existing LUA script, or XML gauge. For LUA, use ipc control 66851 - 66861 to call a specific camera defined by the HotKeySelect 1-10 keys. For XML gauge approach, call these predefined cameras via VIEW_CAMERA_SELECT_# key events.

 

I'm sorry if this looks more complicated than it should be. I'm  just trying to share it as one of viable solution to your initial query of :

 

 

Can I write a lua script to move my seat lower (shift - backspace) by a given number.

+

I only need seat down during landing and up for flight. I was thinking of incorporating it into undercarriage up and down selections

 

That's almost the same case while I was searching for a solution of automatic view switching on Slings/Hoist deployment. And for FSX, i came to a conclusion that the camera definition tweaking is far more easier rather programming a dedicated simconnect client to access and modify its STRUCT EYEPOINT datas and variables which is beyond my knowledge.

Regards,

-xcorez-

Link to comment
Share on other sites

Thanks Pete and Xcorez. I'm going to tackle this again today.

Pete I'm having a go at Lua ( keeps autocorrecting to Lau if I don't watch it which is in my dictionary as it's used at work to refer to Launcher which is a aircraft missile rail ) because I have a " have a go " attitude but I struggle so come here to ask others for help.

Thanks guys!

Graham

Link to comment
Share on other sites

BINGO !

Pete the ipc.control(66151) in a loop, although worked, wasn't accurate and gave different results each time it was used.

 

I went for the camera view in the end suggested by xcorez.

 

[CameraDefinition.012]
Title = Cockpit - Landing POV
Guid = {10EB1B1C-FFAA-44cf-9E23-DE622E32C70C}
Description = 2D Cockpit view for approach/landing sequence.
Origin = Cockpit
ShowPanel = NO
SnapPbhAdjust = Ordinal
SnapPbhReturn = TRUE
PanPbhAdjust = Ordinal
PanPbhReturn = TRUE
Track = None
ShowAxis = FrontOnly
AllowZoom = FALSE
InitialZoom = 0.89
SmoothZoomTime = 1.0
ShowWeather = YES
ShowLensFlare = TRUE
XyzAdjust = TRUE
InitialXyz = 0,0,2.3
InitialPbh = -7,0,0
Category = Cockpit
CycleHidden = YES
HotKeySelect = 8
 

and called this view from my uc down Lua script. Its all running very nice indeed now after a little tweaking. A much more believable view on approach now.

 

Thanks to you both for your time and help ;-)

Graham

Link to comment
Share on other sites

I went for the camera view in the end suggested by xcorez.

...

and called this view from my uc down Lua script. Its all running very nice indeed now after a little tweaking. A much more believable view on approach now.

 

Thanks to you both for your time and help ;-)

Graham

 

Good! I'm pleased you got it sorted.

 

I'm not familiar with CAMERA definitions at all, or really moving the eyepoint. I used to use EZDOK for view positions, now OpusFSX. But because I don't have any cockpit views on the projected screen outside the 'real' cockpit I don't need to raise and lower the view -- I can just lean forward more and look down out the window! ;-)

 

Regards

Pete

Link to comment
Share on other sites

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.