Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!bloom-beacon!EXPO.LCS.MIT.EDU!jim From: jim@EXPO.LCS.MIT.EDU (Jim Fulton) Newsgroups: comp.windows.x Subject: Re: X protocol packets Message-ID: <8812161545.AA00730@EXPO.LCS.MIT.EDU> Date: 16 Dec 88 15:45:12 GMT References: <106@systech.uucp> Sender: daemon@bloom-beacon.MIT.EDU Organization: X Consortium, MIT Laboratory for Computer Science Lines: 74 > Can anyone provide me an explanation of the data within the X protocol > message itself? Like where is the 'k' encoded?? > I just do not understand the format of the data within these X message. Look in your handy Protocol document (sources are provided doc/Protocol/ or in _X_Window_System:_C_Library_and_Protocol_Reference_ by Scheifler, Gettys, and Newman) under Section 11 (named Events). In particular, you want to read the first section describing KeyPress events (in "The Book", this is on pages 443-444). The particular bits are described in Appendix F: Protocol Encoding and are as follows 1 2 event code 1 KEYCODE detail 2 CARD16 sequence number 4 TIMESTAMP time 4 WINDOW root 4 WINDOW event 4 WINDOW child 2 INT16 root-x 2 INT16 root-y 2 INT16 event-x 2 INT16 event-y 2 SETofKEYBUTMASK state If you are using the C lanuage interface Xlib, you'll only need to deal with XKeyEvent structures (from ): typedef struct { int type; /* of event */ unsigned long serial; /* # of last request processed by server */ Bool send_event; /* true if this came from a SendEvent request */ Display *display; /* Display the event was read from */ Window window; /* "event" window it is reported relative to */ Window root; /* root window that the event occured on */ Window subwindow; /* child window */ Time time; /* milliseconds */ int x, y; /* pointer x, y coordinates in event window */ int x_root, y_root; /* coordinates relative to root */ unsigned int state; /* key or button mask */ unsigned int keycode; /* detail */ Bool same_screen; /* same screen flag */ } XKeyEvent; typedef XKeyEvent XKeyPressedEvent; > Like where is the 'k' encoded?? The detail field in the protocol request contains a "keycode" which is a server-dependent number representing the physical key that was pressed just like make/break codes under other operating systems. The state field contains a mask of bits indicating which keyboard modifiers where held down when this key was pressed. Clients are free to use the keycode and state mask directly, although they will usually translate it into a "keysym" which represents the symbol etched on the key. This is usually handled by a library routine (XKeycodeToKeysym in Xlib) as it involves fetching the keyboard mapping (which is a table containing a row for each keycode and a column for each modifier) and then looking up the keysym that corresponds to the pair. Now, this keysym is still just a number (although keysyms, unlike keycodes, are specified by the X Protocol). Applications can then use the keysyms or translate them into "strings" for various character sets using XLookupString and XmuLookup*. However, they should keep in mind that these routines are designed to be used with specific character sets (e.g. ISO Latin-1 for XLookupString) and may not return values for arbitrary combinations of modifiers (esp. function control codes). Jim Fulton MIT X Consortium