(Go: >> BACK << -|- >> HOME <<)

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 get keyboard and mouse input #13520

Open
ahaoboy opened this issue Feb 20, 2024 · 3 comments
Open

How to get keyboard and mouse input #13520

ahaoboy opened this issue Feb 20, 2024 · 3 comments

Comments

@ahaoboy
Copy link
ahaoboy commented Feb 20, 2024

I noticed that in the js script, it seems to use define-section to obtain input, but this command is marked as deprecated. I would like to know if there are other ways to capture user keyboard and mouse input.

I tried to emulate the execution logic of JavaScript in a C plugin, but I did not receive the MPV_EVENT_CLIENT_MESSAGE event. I'm not sure if I've missed something, and I hope someone can point out any mistakes or provide other useful information.

#include <mpv/client.h>
#include <stdio.h>

MPV_EXPORT
int mpv_open_cplugin(mpv_handle *handle)
{
  printf("Hello world from C plugin '%s'!\n", mpv_client_name(handle));
  mpv_command(handle, (const char *[]){"define-section", "mpv_input_js",
                                       "a\n", "default", NULL});
  mpv_command(handle, (const char *[]){"enable-section", "mpv_input_js",
                                       "allow-hide-cursor+allow-vo-dragging", NULL});
  while (1)
  {
    mpv_event *event = mpv_wait_event(handle, -1);
    printf("Got event: %d\n", event->event_id);
    if (event->event_id == MPV_EVENT_SHUTDOWN)
      break;

    if (event->event_id == MPV_EVENT_CLIENT_MESSAGE)
    {
      printf("key event: %d\n", event->event_id);
    }
  }
  return 0;
}
@ahaoboy
Copy link
Author
ahaoboy commented Jun 6, 2024

@avih Could you please help me or give some advice? I'm stuck with this problem for a long time, or is it not possible to get the user's input in the c plugin?
If this problem can be solved, it would be possible to use deno to run js scripts, which would solve all the current problems with js scripts, e.g. performance, network requests, reading and writing to files, etc.
#13608 (comment)

@avih
Copy link
Member
avih commented Jun 6, 2024

I don't know how to help you, sorry. But here are some data points:

Your section looks empty. There won't be any notifications unless the section has some bindings in it (and the bindings need to explicitly target your client id).

You really shouldn't use deprecated functiuons in your code. I don't know what the alternative is, or even if there is an (good) alternative. Not everything you want to do is necessarily possible.

In this case, maybe the keybind command could help, but I don't know how to unbind it (other than rebinding the key to ignore), or how it behaves with regards to the different sections.

@ahaoboy
Copy link
Author
ahaoboy commented Jun 6, 2024

Thank you, it seems that only sdl2 can be used to temporarily solve the problem

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

No branches or pull requests

2 participants