Check for real/fake keypresses in module?

Started by Marsu42, March 02, 2014, 12:22:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Marsu42

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!

a1ex

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.

Marsu42

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) { ... }

a1ex

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)

Marsu42

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.

a1ex

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?

Marsu42

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.

g3gg0

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)
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

Marsu42

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.