Skip to content

Commit 0becaf7

Browse files
committed
libvncclient/rfbproto: Add SendExtendedKeyEvent()
This function sends Qemu extended key events to servers that support such messages. It returns FALSE if the event is not supported.
1 parent 132c138 commit 0becaf7

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

libvncclient/rfbproto.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,9 @@ SetFormatAndEncodings(rfbClient* client)
13501350
if (se->nEncodings < MAX_ENCODINGS)
13511351
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingXvp);
13521352

1353+
if (se->nEncodings < MAX_ENCODINGS)
1354+
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingQemuExtendedKeyEvent);
1355+
13531356
/* client extensions */
13541357
for(e = rfbClientExtensions; e; e = e->next)
13551358
if(e->encodings) {
@@ -1586,6 +1589,31 @@ SendKeyEvent(rfbClient* client, uint32_t key, rfbBool down)
15861589
}
15871590

15881591

1592+
/*
1593+
* SendExtendedKeyEvent.
1594+
*/
1595+
1596+
rfbBool
1597+
SendExtendedKeyEvent(rfbClient* client, uint32_t keysym, uint32_t keycode, rfbBool down)
1598+
{
1599+
rfbQemuExtendedKeyEventMsg ke;
1600+
1601+
/* FIXME: rfbQemuEvent also covers audio events, but this model for checking
1602+
* for supported messages is somewhat limited, so I'll leave this as is for
1603+
* now.
1604+
*/
1605+
if (!SupportsClient2Server(client, rfbQemuEvent)) return FALSE;
1606+
1607+
memset(&ke, 0, sizeof(ke));
1608+
ke.type = rfbQemuEvent;
1609+
ke.subtype = 0; /* key event subtype */
1610+
ke.down = rfbClientSwap16IfLE(!!down);
1611+
ke.keysym = rfbClientSwap32IfLE(keysym);
1612+
ke.keycode = rfbClientSwap32IfLE(keycode);
1613+
return WriteToRFBServer(client, (char *)&ke, sz_rfbQemuExtendedKeyEventMsg);
1614+
}
1615+
1616+
15891617
/*
15901618
* SendClientCutText.
15911619
*/
@@ -2073,6 +2101,10 @@ HandleRFBServerMessage(rfbClient* client)
20732101

20742102
#endif
20752103

2104+
case rfbEncodingQemuExtendedKeyEvent:
2105+
SetClient2Server(client, rfbQemuEvent);
2106+
break;
2107+
20762108
default:
20772109
{
20782110
rfbBool handled = FALSE;

rfb/rfbclient.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,17 @@ extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
570570
* @return true if the key event was send successfully, false otherwise
571571
*/
572572
extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
573+
/**
574+
* The same as SendKeyEvent, except a key code will be sent along with the
575+
* symbol if the server supports extended key events.
576+
* @param client The client through which to send the key event
577+
* @param keysym An rfbKeySym defined in rfb/keysym.h
578+
* @param keycode An XT key code
579+
* @param down true if this was a key down event, false otherwise
580+
* @return true if the extended key event is supported and was sent
581+
* successfully, false otherwise
582+
*/
583+
extern rfbBool SendExtendedKeyEvent(rfbClient* client, uint32_t keysym, uint32_t keycode, rfbBool down);
573584
/**
574585
* Places a string on the server's clipboard. Use this function if you want to
575586
* be able to copy and paste between the server and your application. For

0 commit comments

Comments
 (0)