diff --git a/src/libguac/guacamole/protocol.h b/src/libguac/guacamole/protocol.h index a3e6c181..fd824af6 100644 --- a/src/libguac/guacamole/protocol.h +++ b/src/libguac/guacamole/protocol.h @@ -106,6 +106,32 @@ int guac_protocol_send_disconnect(guac_socket* socket); int guac_protocol_send_error(guac_socket* socket, const char* error, guac_protocol_status status); +/** + * Sends a key instruction over the given guac_socket connection. + * + * If an error occurs sending the instruction, a non-zero value is + * returned, and guac_error is set appropriately. + * + * @param socket + * The guac_socket connection to use. + * + * @param keysym + * The X11 keysym of the key that was pressed or released. + * + * @param pressed + * Non-zero if the key represented by the given keysym is currently + * pressed, zero if it is released. + * + * @param timestamp + * The server timestamp (in milliseconds) at the point in time this key + * event was acknowledged. + * + * @return + * Zero on success, non-zero on error. + */ +int guac_protocol_send_key(guac_socket* socket, int keysym, int pressed, + guac_timestamp timestamp); + /** * Sends a log instruction over the given guac_socket connection. This is * mainly useful in debugging. diff --git a/src/libguac/protocol.c b/src/libguac/protocol.c index a5fe3e9a..dba9c56e 100644 --- a/src/libguac/protocol.c +++ b/src/libguac/protocol.c @@ -615,6 +615,24 @@ int guac_protocol_send_identity(guac_socket* socket, const guac_layer* layer) { } +int guac_protocol_send_key(guac_socket* socket, int keysym, int pressed, + guac_timestamp timestamp) { + + int ret_val; + + guac_socket_instruction_begin(socket); + ret_val = + guac_socket_write_string(socket, "3.key,") + || __guac_socket_write_length_int(socket, keysym) + || guac_socket_write_string(socket, pressed ? ",1.1," : ",1.0,") + || __guac_socket_write_length_int(socket, timestamp) + || guac_socket_write_string(socket, ";"); + + guac_socket_instruction_end(socket); + return ret_val; + +} + int guac_protocol_send_lfill(guac_socket* socket, guac_composite_mode mode, const guac_layer* layer, const guac_layer* srcl) {