Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent event propagation? #57

Closed
WilixLead opened this issue Feb 19, 2018 · 10 comments
Closed

How to prevent event propagation? #57

WilixLead opened this issue Feb 19, 2018 · 10 comments
Labels

Comments

@WilixLead
Copy link

I can't find way to prevent event. Can libuiohook do it?
Will be cool prevent event after receiving (optionally)

@kwhat
Copy link
Owner

kwhat commented Feb 19, 2018

Hi, It is possible for Windows and OS X systems, however, it is not currently possible on Linux or Unix. To use this functionality, you need to set the reserved flag of the uiohook_event structure to 0x1 when you recieve the event on callback. This flag must be set synchronously on the same thread as the callback is received on. So far, only the mask 1 >> 0 is supported for the reserved field.

@kwhat kwhat added the question label Feb 19, 2018
@WilixLead
Copy link
Author

Thank you!
But. I use parts of code from examples and my code looks like this:

void dispatch_proc(uiohook_event * const event) {
  switch (event->type) {
    ....
    case EVENT_KEY_PRESSED:
    case EVENT_KEY_RELEASED:
    case EVENT_KEY_TYPED:
    case EVENT_MOUSE_PRESSED:
    case EVENT_MOUSE_RELEASED:
    case EVENT_MOUSE_CLICKED:
    case EVENT_MOUSE_MOVED:
    case EVENT_MOUSE_DRAGGED:
    case EVENT_MOUSE_WHEEL:
      event->reserved = 0x1;
      ......
    break;
  }
}

But events still emits to the system. What I'm doing wrong?

@kwhat
Copy link
Owner

kwhat commented Feb 20, 2018

That looks correct, which branch are you compiling? The master branch is probably broken and 1.1 is the current stable.

@WilixLead
Copy link
Author

I use 1.1 branch. Some later I try remove current version of libuiohook and clone clean 1.1. But I think it is not help.
What should happen if I prevent key? When I type something and always set reserverd = 0x1, nothing will be typed (in notepad or terminal for example) ?

@kwhat
Copy link
Owner

kwhat commented Feb 28, 2018

Yes, if you set the reserved flag, it will prevent the event it was set for from propagating. So if it was a mouse move event, the mouse will not move. If it was a key down and key up, you will not be able to type.

@kwhat
Copy link
Owner

kwhat commented Feb 28, 2018

Please post the code you are using for the callback so I may better help you.

@kwhat
Copy link
Owner

kwhat commented Feb 28, 2018

I am not sure if it matters in your implementation, but the reserved flag must be set on the same thread context that it was called from. So you cannot copy the memory to a different thread.

@WilixLead
Copy link
Author

Please look at this file https://github.com/WilixLead/iohook/blob/master/src/iohook.cc
For tests I just make this:

case EVENT_KEY_PRESSED:
    case EVENT_KEY_RELEASED:
    case EVENT_KEY_TYPED:
    case EVENT_MOUSE_PRESSED:
    case EVENT_MOUSE_RELEASED:
    case EVENT_MOUSE_CLICKED:
    case EVENT_MOUSE_MOVED:
    case EVENT_MOUSE_DRAGGED:
    case EVENT_MOUSE_WHEEL:
      event->reserved = 0x1; // <----- THIS
      uiohook_event event_copy;
      memcpy(&event_copy, event, sizeof(uiohook_event));

As I think, It should prevent all propagation. But really no :(
Where Im wrong?

@pigfrown
Copy link

Is it still the case that preventing event propagation is not possible on *nix?

If so are there any plans to add this functionality?

Thanks

@kwhat
Copy link
Owner

kwhat commented Oct 21, 2020

It's not possible on X11 due to some technical limitations and I doubt that will ever change. It maybe possible on Wayland, but that hasn't really seen widespread adoption thus far. Migrating this library to wayland is going to take substantial effort and I haven't really looked into it much at this point. If anyone really wants this functionality, start looking into wayland to see this maybe possible. I only have so many hours in a day and right now 2.2 getting finalized and a 3.0 refactor to fix several other long standing issues are a priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants