示例#1
0
        void ProcessRawEvent(ref XGenericEventCookie cookie)
        {
            lock (Sync)
            {
                unsafe
                {
                    XIRawEvent raw = *(XIRawEvent *)cookie.data;
                    XIMouse    mouse;
                    XIKeyboard keyboard;

                    switch (raw.evtype)
                    {
                    case XIEventType.RawMotion:
                        if (GetMouseDevice(raw.deviceid, out mouse))
                        {
                            ProcessRawMotion(mouse, ref raw);
                        }
                        break;

                    case XIEventType.RawButtonPress:
                    case XIEventType.RawButtonRelease:
                        if (GetMouseDevice(raw.deviceid, out mouse))
                        {
                            float       dx, dy;
                            MouseButton button = X11KeyMap.TranslateButton(raw.detail, out dx, out dy);
                            mouse.State[button] = raw.evtype == XIEventType.RawButtonPress;
                            if (mouse.ScrollX.number == -1 && mouse.ScrollY.number == -1)
                            {
                                mouse.State.SetScrollRelative(dx, dy);
                            }
                        }
                        break;

                    case XIEventType.RawKeyPress:
                    case XIEventType.RawKeyRelease:
                        if (GetKeyboardDevice(raw.deviceid, out keyboard))
                        {
                            Key key;
                            if (KeyMap.TranslateKey(raw.detail, out key))
                            {
                                keyboard.State[key] = raw.evtype == XIEventType.RawKeyPress;
                            }
                        }
                        break;
                    }
                }
            }
        }
示例#2
0
        private void ProcessEvents()
        {
            var display = API.DefaultDisplay;

            using (new XLock(display))
            {
                Functions.XQueryKeymap(display, keys);
                for (var keycode = 0; keycode < 256; keycode++)
                {
                    var pressed = ((keys[keycode >> 3] >> (keycode & 0x07)) & 0x01) != 0;
                    Key key;
                    if (KeyMap.TranslateKey(keycode, out key))
                    {
                        state[key] = pressed;
                    }
                }
            }
        }