in reply to Re: Re: SendEvent in X11::Protocol
in thread SendEvent in X11::Protocol

Well I figured it out, mostly. I thought that the event field of the hash was used for the event to send, but now I know it isn't. I'm not sure what it is for, perhaps an event ID.

The detail field is where you can specify what to send for a KeyPress event. But it's not the ASCII value, or even the X keysym (which, for letters, are mapped to ASCII anyway). The detail field actually takes a keycode, which is simply a number representing a certain keyboard key.

All the keys on a keyboard are coded according to your modmap, and it doesn't really have any relation to what the key being pressed is supposed to do, it just says "Key #25 was pressed". Internally, X translates the keycode (specific to your keyboard setup) to the keysym (portable across X), depending on what is in the state field, so that the statement becomes "The letter 'w' was given".

The state field tells what modifier keys should be taken into consideration. 0 means none, 1 means SHIFT (so you'd get 'W' instead of 'w'), etc. It's probably taken as a bit vector to specify combinations of SHIFT, ALT, CTRL, META, and SUPER, but I didn't test fully to find out which bit is which. I'm not exactly sure what the code field does, but it seems to be another indicator of the event type. 0 and 1 are invalid, 2 seems to work for keypresses, and anything higher doesn't seem to do anything (in my very limited testing) except for 15 and 18, which specify events for window notifications (focus in/out, and map/unmap I think).

The other fields are rather self-explanatory, except for sequence_number about which I have no idea. In this module, the time field can also be given 'CurrentTime', which does the obvious, although I'm not sure X cares about the time.

I'm still having a problem getting the event to be delivered to the correct window, but I haven't done extensive testing. Updates as they come.

PS. You can get a look at your modmap to find out your specific keycodes by using the command: xmodmap -pk