Jump to content
The simFlight Network Forums

Recommended Posts

Posted

In the FSUIPC: LUA Library Reference, about event.key(keycode, shifts, “function-name”) it says 'Note that repeated keys (auto-repeats resulting from holding the keys down) are not processed.'

However I would like to have repeated keys processed for some keys. Is it possible?

FSUIPC 3.98a, OS: WinXP, FS9.

/Jonny

Posted
In the FSUIPC: LUA Library Reference, about event.key(keycode, shifts, “function-name”) it says 'Note that repeated keys (auto-repeats resulting from holding the keys down) are not processed.'

However I would like to have repeated keys processed for some keys. Is it possible?

Why not just detect the press, detect the release, and repeat whatever it is you want to repeat yourself, at your desired rate? That's a more elegant and controllable way, don't you think? If FSUIPC tried to pass them on it would either have to queue them, waiting for the event processing to finish, or forcibly restart it to re-enter it. Neither of those ways is very nice, and any other way could give an irregular or unwanted repeat rate out of your control.

In other words, the reason I designed it so that repeats don't result in events is because it is not necessary to depend on the standard Windows or keyboard auto-repeat when you can do it with more control yourself. (It's the same for button pressing of course).

Regards

Pete

Posted

I will explain a little more, I will use one key to increase settings of HDG, NAV1 freq, COM2 freq and so on.

And other keys to inc and dec fraqctions as well. When I press the key I would like to step the settings up or down.

Almost in the same way when you use the mouse on the panel.

Could you give a short example how to program this?

/Jonny

Posted
I will explain a little more, I will use one key to increase settings of HDG, NAV1 freq, COM2 freq and so on.

And other keys to inc and dec fraqctions as well. When I press the key I would like to step the settings up or down.

Almost in the same way when you use the mouse on the panel.

Not sure why you want to program this as a Lua plug-in. Wouldn't direct assignment to those functions be better, easier?

Could you give a short example how to program this?

Quite honestly, if this is all you want to do and you really do want it in Lua, I would simply assign the keypress to run the Lua program. Why use the event library?

If you really want to use the event library I think it might need two Lua plug-ins, one to process the events and the other to operate the inc/dec.

Regards

Pete

Posted

This is my start of programming.

-- prog to handle the aircrafts radios from the keyboard

-- setting heading bug, altitude bug etc.

-- setting radiofrequencies

-- aktivate autopiloten

-- allt från tangentbordet, kräver omställning av vissa tangenter genom val på andra tangenter.

-- t.ex. när man väljer HDG BUG skall öka-minska tangenterna ställa om headingen,

-- när man väljer NAV radio1 skall öka-minska och dec-öka-minska sändas till just NAV1 radion.

-- all ipc.display() function is for debugg purpuse during programming.

select = 0 -- 0=NAV1 radio 1=NAV2radio 2=COM1radio 3=COM2radio

function swap_label(keycode, shifts) -- <-> label

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nlabel = <-> label")

if select == 0 then ipc.control(66448, 0) end --NAV1 RADIO SWAP

if select == 1 then ipc.control(66452, 0) end --NAV2 RADIO SWAP

if select == 2 then ipc.control(66372, 0) end -- COM1 RADIO SWAP

if select == 3 then ipc.control(66444, 0) end -- COM2 RADIO SWAP

end

function whole_inc(keycode, shifts) -- SEL + label

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nlabel = SEL + label")

if select == 0 then ipc.control(65641, 0) end --NAV1 RADIO WHOLE INC

if select == 1 then ipc.control(65645, 0) end --NAV2 RADIO WHOLE INC

if select == 2 then ipc.control(65637, 0) end -- COM1 RADIO WHOLE INC

if select == 3 then ipc.control(66437, 0) end -- COM2 RADIO WHOLE INC

end

function whole_dec(keycode, shifts) -- SEL - label

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nlabel = SEL - label")

if select == 0 then ipc.control(65640, 0) end --NAV1 RADIO WHOLE DEC

if select == 1 then ipc.control(65644, 0) end --NAV2 RADIO WHOLE DEC

if select == 2 then ipc.control(65636, 0) end -- COM1 RADIO WHOLE DEC

if select == 3 then ipc.control(66436, 0) end -- COM2 RADIO WHOLE DEC

end

function fract_inc(keycode, shifts) -- ledig

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nlabel = punkt ledig")

if select == 0 then ipc.control(65643, 0) end --NAV1 RADIO FRACT_INC

if select == 1 then ipc.control(65647, 0) end --NAV2 RADIO FRACT_INC

if select == 2 then ipc.control(65639, 0) end -- COM1 RADIO FRACT_INC

if select == 3 then ipc.control(66440, 0) end -- COM2 RADIO FRACT_INC

end

function fract_dec(keycode, shifts) -- ledig

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nlabel =mm minus ledig")

if select == 0 then ipc.control(65642, 0) end --NAV1 RADIO FRACT_DEC

if select == 1 then ipc.control(65646, 0) end --NAV2 RADIO FRACT_DEC

if select == 2 then ipc.control(65638, 0) end -- COM1 RADIO FRACT_DEC

if select == 3 then ipc.control(66438, 0) end -- COM2 RADIO FRACT_DEC

end

function com_sel(keycode, shifts) -- COM SEL label

if select > 2 then

select = 2

else select = 3

end

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nselect="..select.."\nlabel= COM SEL label")

end

function nav_sel(keycode, shifts) -- NAV SEL label

if select > 0 then

select = 0

else select = 1

end

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nselect="..select.."\nlabel= NAV SEL label")

end

-- Enable event on keys being pressed (only)

event.key(78, 8, "swap_label") -- <-> label n-key

event.key(77, 8, "whole_inc") -- SEL + label m-key

-- when I press this key I would like the incremation in the function to step step-step-step-step as long as i press the key

event.key(188, 8, "whole_dec") -- SEL - label komma_key

-- same for this

event.key(190, 8, "fract_inc") -- ledig punkt_key

-- and for this

event.key(189, 8, "fract_dec") -- ledig minus_key

-- and for this

event.key(72, 8, "com_sel") -- COM SEL label h_key

-- first press select COM1 next press select Com2, next pres selectt com1 and so on

event.key(74, 8, "nav_sel") -- NAV SEL label j_key

-- same for select nav radio

Hope you understand my program and can give me a hint!

/Jonny

Posted

Hope you understand my program and can give me a hint!

Okay. i see why you want the event to repeat with keypress repetition.

I could consider adding such a facility. I'll think about it and let you know. But meanwhile there are at least two ways of doing it.

First there is the more usual way to do it, without events, just using normal Lua assignments. Use a free user FSUIPC offset, like 0x66C0, for your "select" variable. Assign the keypress to increment that cyclically, or whatever (or use two variables, 0x66C0 and 0x66C1). Use Offset Byte Cyclic Increment, for example. you'll find this is the FSUIPC drop-down assignments list.

Then each of the inc/dec routines is replaced by a Lua program like this example (say "WholeInc.lua"):

select = ipc.readUB(0x66C0)
if select == 0 then ipc.control(65641, 0) end --NAV1 RADIO WHOLE INC
if select == 1 then ipc.control(65645, 0) end --NAV2 RADIO WHOLE INC
if select == 2 then ipc.control(65637, 0) end -- COM1 RADIO WHOLE INC
if select == 3 then ipc.control(66437, 0) end -- COM2 RADIO WHOLE INC

Assign the WholeInc key press to "Lua WholeInc", which will then appear in the drop-down assignments list (use the RELOAD button after saving the new Lua programs).

And so on. The repeating key action is then automatically taken care of.

The other way, still using events, is more complicated. You'd still have the separate Lua's like "WholeInc.lua" but now they'd be called by the event processing Lua thus:

function whole_inc(keycode, shifts)
   ipc.runlua("WholeInc", select)
end

and the "WholeInc.lua" program would loop forever:

select = ipcPARAM
while true do
   if select == 0 then ipc.control(65641, 0) end --NAV1 RADIO WHOLE INC
   if select == 1 then ipc.control(65645, 0) end --NAV2 RADIO WHOLE INC
   if select == 2 then ipc.control(65637, 0) end -- COM1 RADIO WHOLE INC
   if select == 3 then ipc.control(66437, 0) end -- COM2 RADIO WHOLE INC
   ipc.sleep(100) -- this is 10 incs per sec. Adjust to taste
end

You'd then need to process the keyup events too (downup = 2), calling a function to execute ipc.macro("Luakill ....") to kill the repeating Lua.

The first solution is better and doesn't involve any complication or permanently loaded Lua programs. The small programs just run when you press the keys.

I will look into the possibility of a "downup" parameter for event.key which specifies repeats required too, but I can't promise anything. I do feel you've made it rather more complicated than you need to.

Feel free to ask further questions if anything isn't clear.

Regards

Pete

Posted

I think your hints will work well, I will test it later on and let you know.

Okay, but don't discard your code above yet, as I've looked at my code for the "key" events and I think I can accommodate a "repeat" option quite easily. If I do you can try both ways and see which operates better for you.

I'll post again when and if I have anything for you to try.

Regards

Pete

Posted

I'll post again when and if I have anything for you to try.

Okay. the change was pretty easy, so it is done already.

Check the Updates announcement at the top of the Forum. You need to download FSUIPC 3.989b or 4.625. The event.key() facility is extended as follows:

The Lua event.key facilities can now provide event calls on keypress repetition. To receive repeats the "downup" parameter must be specified, with '4' added to the documented values, so that:

4 = pressed +repeats

5 = pressed +repeats

6 = same as 2, only release

7 = pressed, + repeats, +release[/size]

The "downup" parameter in the called function will be 3 for a repeated press, 1 for an initial press and 0 for a release.

I used your Lua, from your earlier post, to test it with. It works fine if you just change these lines:

event.key(77, 8, 4, "whole_inc") -- SEL + label m-key
event.key(188, 8, 4, "whole_dec") -- SEL - label komma_key
event.key(190, 8, 4, "fract_inc") -- ledig punkt_key
event.key(189, 8, 4, "fract_dec") -- ledig minus_key

Have fun!

Regards

Pete

Posted

Hi Pete!

Thanks for all help.

I have tested the first hint and it works very fine.

Here is my code:

-- LUA_mode_02.lua

-- prog to handle the aircrafts radios from the keyboard

-- setting heading bug, altitude bug etc.

-- setting radiofrequencies

-- aktivate autopiloten

-- allt från tangentbordet, kräver omställning av vissa tangenter genom val på andra tangenter.

-- t.ex. när man väljer HDG BUG skall öka-minska tangenterna ställa om headingen,

-- när man väljer NAV radio1 skall öka-minska och dec-öka-minska sändas till just NAV1 radion.

-- all ipc.display() function is for debugg purpuse during programming.

select = 0 -- 0=NAV1 radio, 1=NAV2radio, 2=COM1radio, 3=COM2radio

function swap_label(keycode, shifts) -- <-> label

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nlabel = <-> label")

if select == 0 then ipc.control(66448, 0) end --NAV1 RADIO SWAP

if select == 1 then ipc.control(66452, 0) end --NAV2 RADIO SWAP

if select == 2 then ipc.control(66372, 0) end -- COM1 RADIO SWAP

if select == 3 then ipc.control(66444, 0) end -- COM2 RADIO SWAP

end

function com_sel(keycode, shifts) -- COM SEL label

if ipc.readUB(0x66C0) > 2 then

ipc.writeUB(0x66C0, 2)

select = 2

else

ipc.writeUB(0x66C0, 3)

select = 3

end

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nselect="..select.."\nlabel= COM SEL label")

end

function nav_sel(keycode, shifts) -- NAV SEL label

if ipc.readUB(0x66C0) > 0 then

ipc.writeUB(0x66C0, 0)

select = 0

else

ipc.writeUB(0x66C0, 1)

select = 1

end

ipc.display("keycode="..keycode.."\nshifts="..shifts.."\nselect="..select.."\nlabel= NAV SEL label")

end

-- Enable event on keys being pressed (only)

event.key(78, 8, "swap_label") -- <-> label n-key

-- these keys are assigned to start a LUA prog.

-- event.key(77, 8, 1, "whole_inc") -- SEL + label m-key

-- event.key(188, 8, 1, "whole_dec") -- SEL - label komma_key

-- event.key(190, 8, 1, "fract_inc") -- ledig punkt_key

-- event.key(189, 8, 1, "fract_dec") -- ledig minus_key

event.key(72, 8, "com_sel") -- COM SEL label h_key

event.key(74, 8, "nav_sel") -- NAV SEL label j_key

-- ************************************************** --

-- four LUA-prog

-- LUA_whole_dec.lua

select = ipc.readUB(0x66C0)

if select == 0 then ipc.control(65640, 0) end --NAV1 RADIO WHOLE DEC

if select == 1 then ipc.control(65644, 0) end --NAV2 RADIO WHOLE DEC

if select == 2 then ipc.control(65636, 0) end -- COM1 RADIO WHOLE DECnnn

if select == 3 then ipc.control(66436, 0) end -- COM2 RADIO WHOLE DEC

ipc.sleep(200)

-- LUA_whole_inc.lua

select = ipc.readUB(0x66C0)

if select == 0 then ipc.control(65641, 0) end --NAV1 RADIO WHOLE INC

if select == 1 then ipc.control(65645, 0) end --NAV2 RADIO WHOLE INC

if select == 2 then ipc.control(65637, 0) end -- COM1 RADIO WHOLE INC

if select == 3 then ipc.control(66437, 0) end -- COM2 RADIO WHOLE INC

ipc.sleep(200)

-- LUA_fract_dec.lua

select = ipc.readUB(0x66C0)

if select == 0 then ipc.control(65642, 0) end --NAV1 RADIO FRACT_DEC

if select == 1 then ipc.control(65646, 0) end --NAV2 RADIO FRACT_DEC

if select == 2 then ipc.control(65638, 0) end -- COM1 RADIO FRACT_DEC

if select == 3 then ipc.control(66438, 0) end -- COM2 RADIO FRACT_DEC

ipc.sleep(200)

-- LUA_fract_inc.lua

select = ipc.readUB(0x66C0)

if select == 0 then ipc.control(65643, 0) end --NAV1 RADIO FRACT_INC

if select == 1 then ipc.control(65647, 0) end --NAV2 RADIO FRACT_INC

if select == 2 then ipc.control(65639, 0) end -- COM1 RADIO FRACT_INC

if select == 3 then ipc.control(66440, 0) end -- COM2 RADIO FRACT_INC

ipc.sleep(200)

-- END ******************************

Which of your methods are to prefer?

According to FS-framerates or computer performance?

And now another question to this project:

Do you know any way a XML-gauge kan read the FSUIPC-offset: 'select = ipc.readUB(0x66C0)'. I would like a small gauage to see which part is selected for the moment?

Or iIs it possible to use some offset connected to a given XML-event or parameter? An offset which we can do without!!

/Jonny

Posted

Which of your methods are to prefer?

According to FS-framerates or computer performance?

I don't really know -- your preference I think. Try them both out. Your all-in-one Lua is more elegant (now I've added the repeat facility), but the direct assignment one is probably a little more efficient. I shouldn't think there's much in it though.

Do you know any way a XML-gauge kan read the FSUIPC-offset: 'select = ipc.readUB(0x66C0)'. I would like a small gauage to see which part is selected for the moment?

No, no way.

You'd need to copy the value to an L:var created by the gauge. There are Lua facilities to read and write named local variables (L:vars). Check that out.

Regards

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.