The way I did it, I have applications receiving both key press/release events (which are the same regardless of layout) and character input as separate message types. Keyboard drivers know nothing of characters or keyboard layouts. Instead, a key mapper is automatically created for each keyboard and invoked by the UI to generate character messages. Now, I hope that there aren't languages which put things like backspace, arrows keys and the like at different positions or I'm going to have a headache.
Mice and touchpads are registered with the UI in the same way as keyboards, except that they don't have an associated key mapper. They report input with a separate set of codes (movement, scrolling, button states for up to 5 buttons, and absolute position). X and Y axes are reported together in a single input packet, as they of course should be.
For any other type of input (key pressure, joy sticks, etc), applications should probably connect to the device using a separate API capable of receiving any kind of input report and describing what is in them. Joy sticks certainly shouldn't cause cursor movement.
Quote:
Incidentally, this makes it practical to treat the mouse as a very special kind of keyboard: when the mouse moves, send a Mouse{X,Y} event (where Mouse{X,Y} is a keycode) with as press level how much the mouse moved, then immediately send another event that sends the same event but with 0 press level.
This should also make it easier to support joy sticks, since you can send the same Mouse{X,Y} event to move the cursor without adding special support.
But why? What benefits do you get from treating a mouse axis like key pressure? When you see yourself forcing some thing to be some entirely different kind of thing it is usually a sign of something needing to be reworked, especially when you end up with things like separate events for X and Y axis movements. Mouse inputs aren't keys, a mouse is used to point at and interact with things on the screen. Joy sticks again have an entirely different purpose, you don't point at things with a joy stick. Joy sticks are usually found on game pads where there are often several of them, and are used for specialized applications such as games. Axis values mean nothing in themselves without knowing what they represent.
Quote:
I've concluded I can't do better than X11. For each keypress, it can supply an untranslated keycode, whichever modifiers are pressed/active, and the translated character if there is one.
With the traditional processing of PC keyboard input, a single keypress can generate multiple characters if an accent key is pressed followed by another key for which no corresponding accented character exists. For example, ~ followed by G outputs ~g. I recommend keeping to this tradition. Linux forces me to press space in between, or the ~ just doesn't register, which is always a frustration when being used to Windows.