Linux input.h(我将在.NET 中链接到哪个库)

发布于 2024-12-27 06:48:33 字数 679 浏览 3 评论 0原文

我正在使用 Mono C#,想知道“input.h”依赖于哪个物理库? 我搜索过谷歌但没有得到任何结果。

注意更新:这里的目标是在 Linux 中获得键盘和鼠标输入。所以问题是我需要包装什么库来输入。有没有使用“input.h”获取输入的好的 C/C++ 示例?

在 C# 中,要链接到库,您需要执行以下操作::

[DllImport("libX11", EntryPoint = "XOpenDisplay")]
public static extern IntPtr XOpenDisplay(IntPtr display_name);

所以我需要执行与上面相同的操作,但使用输入库。像这样的东西::

[DllImport("libInput ???", EntryPoint = "CreateDevice")]
public static extern IntPtr CreateDevice(int deviceID, ...);

我打算使用这个 键盘输入链接即可开始...

I'm using Mono C# and would like to know what physical library "input.h" is dependent on?
Ive searched google but am not getting anything.

NOTE UPDATE: The goal here is to get Keyboard and Mouse input in Linux. So rly the question is what library do I need to wrap for input. Are there any good C/C++ examples for getting input using "input.h"?

In C# to link to a library you would do something like::

[DllImport("libX11", EntryPoint = "XOpenDisplay")]
public static extern IntPtr XOpenDisplay(IntPtr display_name);

So I need to do the same thing as above but with the input library. Something like::

[DllImport("libInput ???", EntryPoint = "CreateDevice")]
public static extern IntPtr CreateDevice(int deviceID, ...);

I was going to use this Keyboard Input link to get started after I find what library to link to...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我闹别瞎闹 2025-01-03 06:48:37

好吧,我想出了如何通过 X11 获取所有按键和鼠标输入。我正在 OSX 上的 Cocoa 中做一些非常类似的事情。

因此,对于任何想知道我是如何做到这一点的基础知识的人,如果您发现 X11 事件逻辑有任何问题,请告诉我::

// Enable Capture of close box
var atom = XInternAtom(d, "WM_DELETE_WINDOW", false);
XSetWMProtocols(d, w, new IntPtr[]{atom}, 1);       

bool run = true;
while (run)
{
    while (X11.XPending(d) != 0)
    {
        X11.XPeekEvent(d, ref e);

        switch (e.type)
        {
            case (X11.Expose):
                Console.WriteLine("Window Scaled.");
                break;

            case (X11.ClientMessage):
                Console.WriteLine("Window Closed.");
                run = false;
                break;

            case (X11.KeyPress):
                Console.WriteLine("Key pressed: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;

            case (X11.KeyRelease):
                Console.WriteLine("Key released: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;

            case (X11.ButtonPress):
                Console.WriteLine("MouseButton pressed: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;

            case (X11.ButtonRelease):
                Console.WriteLine("MouseButton released: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;
        }

        X11.XNextEvent(d, ref e);

        //Console.WriteLine(e.type.ToString());
    }

    Console.WriteLine("Render GL frame here...");

    // Cursor loc
    /*IntPtr w2, w3;
    int x, y, x2, y2;
    uint mask;
    XQueryPointer(d, w, out w2, out w3, out x, out y, out x2, out y2, out mask);
    Console.WriteLine(string.Format("{0}, {1}", x, y));
    Console.WriteLine(string.Format("{0}, {1}", x2, y2));*/

    System.Threading.Thread.Sleep(500);
}

Ok so I figured out how to get all the key and mouse input through X11. I'm doing something very similar in Cocoa on OSX.

So for anyone wondering the basics of how I did it, Here ya go and let me know if you see anything wrong with the X11 event logic::

// Enable Capture of close box
var atom = XInternAtom(d, "WM_DELETE_WINDOW", false);
XSetWMProtocols(d, w, new IntPtr[]{atom}, 1);       

bool run = true;
while (run)
{
    while (X11.XPending(d) != 0)
    {
        X11.XPeekEvent(d, ref e);

        switch (e.type)
        {
            case (X11.Expose):
                Console.WriteLine("Window Scaled.");
                break;

            case (X11.ClientMessage):
                Console.WriteLine("Window Closed.");
                run = false;
                break;

            case (X11.KeyPress):
                Console.WriteLine("Key pressed: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;

            case (X11.KeyRelease):
                Console.WriteLine("Key released: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;

            case (X11.ButtonPress):
                Console.WriteLine("MouseButton pressed: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;

            case (X11.ButtonRelease):
                Console.WriteLine("MouseButton released: " + e.KeyEvent.keycode.ToString());
                //run = false;
                break;
        }

        X11.XNextEvent(d, ref e);

        //Console.WriteLine(e.type.ToString());
    }

    Console.WriteLine("Render GL frame here...");

    // Cursor loc
    /*IntPtr w2, w3;
    int x, y, x2, y2;
    uint mask;
    XQueryPointer(d, w, out w2, out w3, out x, out y, out x2, out y2, out mask);
    Console.WriteLine(string.Format("{0}, {1}", x, y));
    Console.WriteLine(string.Format("{0}, {1}", x2, y2));*/

    System.Threading.Thread.Sleep(500);
}
离旧人 2025-01-03 06:48:36

linux/input.h 只是一堆常量和结构体;它背后没有库,因为您应该自己打开/访问事件子系统。

linux/input.h is just a bunch of constants and structs; there is no library behind it since you're supposed to open/access the event subsystem yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文