Author Topic: Check for real/fake keypresses in module?  (Read 4654 times)

Marsu42

  • Contributor
  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Check for real/fake keypresses in module?
« 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!

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: Check for real/fake keypresses in module?
« Reply #1 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.

Marsu42

  • Contributor
  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Re: Check for real/fake keypresses in module?
« Reply #2 on: March 02, 2014, 12:44:43 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:

Code: [Select]
static unsigned int mymodule_keypress_cbr(unsigned int ctx, bool is_fake) { ... }

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: Check for real/fake keypresses in module?
« Reply #3 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)

Marsu42

  • Contributor
  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Re: Check for real/fake keypresses in module?
« Reply #4 on: March 03, 2014, 07:53:23 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 12564
Re: Check for real/fake keypresses in module?
« Reply #5 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?

Marsu42

  • Contributor
  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Re: Check for real/fake keypresses in module?
« Reply #6 on: March 03, 2014, 09:39:44 AM »
g3gg0?

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

  • Developer
  • Hero Member
  • *****
  • Posts: 3183
Re: Check for real/fake keypresses in module?
« Reply #7 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)
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: paypal@g3gg0.de
ONLY donate for things we have done, not for things you expect!

Marsu42

  • Contributor
  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Re: Check for real/fake keypresses in module?
« Reply #8 on: March 03, 2014, 10:08:32 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.