BlueMonkMN's picture

OpenTK.Input.Key Numeric Keypad Enter?

It appears that there is no enumeration member to represent the enter key on the numeric keypad. Is this true? Is it intentional? Do some platforms not distinguish between numeric keypad enter and the other enter key?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

The original plan was to have the input system independent from the GameWindow, so you could use it with GLControl or anything else. To do this, the KeyboardDriver needs to "preview" keyboard messages before they reach their destination (i.e. Windows.Forms).

This works on Windows (using the concept of subclassing), but I haven't yet found a way to implement this on X11. Some messages are delivered to the KeyboardDriver (and then put back on the event queue so that Mono can process them), but others are consumed by Mono before we have a chance to receive them.

If you know of a way to preview XEvents that are sent to a specific window, I'd love to hear it. Alternatively, this could be implemented by polling the keyboard state with XQueryPointer and XTranslateCoordinates. As always, patches welcome!

BlueMonkMN's picture

I guess I'm still not understanding the code adequately -- can you answer either of these questions for me:
1. Is there any way to get keyboard information (including distinct left and right Ctrl key presses) in X11 if I'm using Windows Forms / GLControl?
2. How does OpenTK's keyboard processing work for X11?

the Fiddler's picture
  1. No, if you wish to stay within .Net. Probably yes, if you pinvoke XQueryPointer and get the data from X11 directly.
  2. The GameWindow pinvokes X11 to create a window and processes native keyboard messages. In other words, it does not use Windows.Forms.

The problem is that Windows.Forms consume keyboard messages before OpenTK has a chance to process them, which is why OpenTK.Input.KeyboardDevice only works with the GameWindow.

BlueMonkMN's picture

Is there anything similar to DirectX.DirectInput available from this environment? I was using DirectInput in Windows, but abandoned it when I abandoned the rest of DirectX. You'd think there'd be something.

the Fiddler's picture

Not at this point - input is currently tied to the GameWindow. Patches are always welcome, however.

BlueMonkMN's picture

That's what I'm asking -- is any such technology possible in the Linux environment. (I wasn't referring specifically to OpenTK, but Linux in general.) How does one more directly access keyboard hardware in Linux? If you can tip me off on where to begin, I might be able to figure something out.

the Fiddler's picture

As far as I can see, the simplest way is to use XQueryPointer:
XQueryPointer returns the current logical state of the keyboard buttons
and the modifier keys in mask_return. It sets mask_return to the bit-
wise inclusive OR of one or more of the button or modifier key bitmasks
to match the current state of the mouse buttons and the modifier keys.

It is also possible to open the /dev/input/event* devices nodes and read raw keyboard and mouse events. These work pretty much like raw input (edit: or DirectInput) on windows: you get low-latency, raw mouse / keybord events, support for multiple devices (e.g. if you have two keyboards, you can use them indepedently - awesome for arcade games), but you don't benefit from pointer balistics (acceleration curves, as applied by the XServer) and some distributions don't set the correct permissions.

Edit: It seems I am mistaken: XQueryPointer returns the state for the modifier keys only. Unless there is some other way to poll the state of the keyboard on X11, reading raw events may be the only solution.

Edit 2: Ok, another possible solution is to use the X keyboard extension (XKB), as described here (link is a pdf, so click accordingly). Of interest is page 23, which defines XkbGetState that can be used to query the state of the keyboard.

Edit 3: Ok, I've found some C code for SDL that opens and reads mouse events from /dev/input/event*. Attaching it so it doesn't get lost.

AttachmentSize
evdev_multiple_mice.cpp9.82 KB
BlueMonkMN's picture

OK, not being very experienced in developing for Linux, I'm having a heckuva time trying to figure out how to get/use XKB. After some searching I have determined (I think) that the functions I want are in /usr/lib/libX11.so.6. I tried the following code in C# in MonoDevelop and got a reasonable result ("1.0"):

[DllImport("libX11.so.6")] public static extern bool XkbLibraryVersion(out int maj, out int min);
...
int maj=1, min=0;
XkbLibraryVersion(out maj, out min);
Console.WriteLine("{0}.{1}\n", maj, min);

But now I'm trying to call XkbGetState, and I don't know what to pass for the device parameter. I would like to pass XkbUseCoreKbd, but I can't find the value of this constant anywhere on my system. So I tried downloading and installing (apt-get install) libxkbfile-dev. But I still can't find it. And when I try to compile the following C code with g++, I get an error "undefined reference to `XkbLibraryVersion'":

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
 
int main(int argc, char *argv[])
{
   int maj, min;
   XkbLibraryVersion(&maj, &min);
   printf("%d.%d\n", maj, min);
   return 0;
}

I'm kinda lost, but I think I could get somewhere if I just had some key piece of info, like how to get XKB header files.

the Fiddler's picture

Quoting from apple:

#define	XkbUseCoreKbd		0x0100

Google is th easiest way to locate such constants.

The -dev package shoould include the necessary headers. Maybe you are missing libx11-dev?

BlueMonkMN's picture

I would hope there are easier ways than Google -- I searched Google for a while and still couldn't find it because I didn't know if it was a #define or some other form of constant. So I didn't bother to search for #define XkbUseCoreKbd because I was having such poor luck that I figured it wouldn't work. I see now that it would have. I'll try installing libx11-dev next time I'm booted into Ubuntu.

Do you know if libX11.so.6 is the right library to link to? I think I noticed that I have a libX11.so, which I am guessing might be a link to the current libX11, but I thought I tried linking to that earlier and it didn't work... maybe libxkbfile-dev installed it? I figure I want to link to the most reliable file.