Magic Lantern Forum

Developing Magic Lantern => General Development => Topic started by: Marsu42 on March 02, 2014, 12:22:18 PM

Title: Check for real/fake keypresses in module?
Post by: Marsu42 on March 02, 2014, 12:22:18 PM
In the core, I can tell fake keypresses from real ones with an IS_FAKE(event) check & only then look at event->param keycode - but modules only get the button code. So how do I check for fake keypresses in a module? Thanks!
Title: Re: Check for real/fake keypresses in module?
Post by: a1ex on March 02, 2014, 12:33:42 PM
This one looks a bit ugly, but possible. Right now you could use CBR_KEYPRESS_RAW, which will give access to the raw GUI event (with camera-specific button codes). There you can use IS_FAKE, and you can get the portable keypress with module_translate_key.

Source: handle_module_keys from module.c.
Title: Re: Check for real/fake keypresses in module?
Post by: Marsu42 on March 02, 2014, 12:44:43 PM
Quote from: a1ex on March 02, 2014, 12:33:42 PM
Source: handle_module_keys from module.c.

Thanks, will do - though you could think about adding a core function for a simpler IS_FAKE check in modules, I might note be the only one using it in the future.... or you simply amend the CBR_KEYPRESS with a bool, doesn't hurt if it's not used in every module:


static unsigned int mymodule_keypress_cbr(unsigned int ctx, bool is_fake) { ... }
Title: Re: Check for real/fake keypresses in module?
Post by: a1ex on March 02, 2014, 01:10:31 PM
I like the idea, though I think g3gg0 designed these functions to accept a single parameter (important? not sure what's the reason behind it)
Title: Re: Check for real/fake keypresses in module?
Post by: Marsu42 on March 03, 2014, 07:53:23 AM
Quote from: a1ex on March 02, 2014, 01:10:31 PM
I like the idea, though I think g3gg0 designed these functions to accept a single parameter (important? not sure what's the reason behind it)

Argh, I just looked at it, the whole handler code is really designed for only one argument, not just only for the keypress cbr - I don't see any minimal invasive way to add IS_FAKE to module.c :-\ and really miss function overloading of C++. I guess I'll have to deal it in my module as you described, it doesn't add much overhead since I just replace the handlers and the key translate function would be called anyway from the core.
Title: Re: Check for real/fake keypresses in module?
Post by: a1ex on March 03, 2014, 08:08:49 AM
I did a ugly workaround for passing 2 parameters in CBR_DISPLAY_FILTER (had to define struct display_filter_buffers and force some casts). I'd like to clean this up too and simply pass these parameters to the CBR handler as usual.

g3gg0?
Title: Re: Check for real/fake keypresses in module?
Post by: Marsu42 on March 03, 2014, 09:39:44 AM
Quote from: a1ex on March 03, 2014, 08:08:49 AMg3gg0?

In this case I'd also vote for the addition of a second multiple-use int parameter that is transmitted via the handler. The option to filter fake keystrokes is important, and some newbie module authors might not even know about the issue otherwise and wonder why their module reacts in a certain way.
Title: Re: Check for real/fake keypresses in module?
Post by: g3gg0 on March 03, 2014, 09:45:06 AM
i am on my way to a meeting.
short: in this case i would redesign the ctx to be a pointer to a structure.
and the structure could either be the internal ML structure (would not recommend that)
or it could be a structure designed for the module system. (recommended)
Title: Re: Check for real/fake keypresses in module?
Post by: Marsu42 on March 03, 2014, 10:08:32 AM
Quote from: g3gg0 on March 03, 2014, 09:45:06 AM
or it could be a structure designed for the module system. (recommended)

This sounds like a great & expandable solution, and since there are no binary modules in the wild that would suffer from a broken api I'll wait for this solution and not add a self-contained fix to my current module.