For the past few days, I've been working on an X11 layer to replace SDL in my future applications. All has been nice sailing up until now where I've arrived on stranger tides

Ok, jokes aside, I have this:

Code:
PMEvent.LastKeyDown := XKeySymToKeyCode(Display, XLookupKeySym(@event.xkey, 0));
and
Code:
PMEvent.LastKeyDown := Display, XLookupKeySym(@event.xkey, 0);
Now although both appear to work - they do not work the way they should. The first implementation results in the following behaviour:
q=24, w=25, e=26 and so on for each row of keys on the keyboard
The second implementation returns the 'correct' values and can be reliably fed from Ord() and into char() however pressing up, esc etc results in values over 65,000!

Has anyone come up with a solution to this - or at least can find a way of getting these to match the 'correct' sdl and readkey() keycodes?