@@ -778,6 +778,14 @@ def __init__(
778
778
'Super_L' , 'Super_R' ,
779
779
'Meta_L' , 'Meta_R'
780
780
}
781
+ self .active_modifiers = set ()
782
+ self .MODIFIER_KEYSYMS = {
783
+ 65505 , 65506 , # Shift_L, Shift_R
784
+ 65507 , 65508 , # Control_L, Control_R
785
+ 65513 , 65514 , # Alt_L, Alt_R
786
+ 65027 , # ISO_Level3_Shift (AltGr)
787
+ 65511 , 65512 , # Meta_L, Meta_R / Super_L, Super_R
788
+ }
781
789
self .gst_webrtc_app = gst_webrtc_app
782
790
self .loop = asyncio .get_event_loop ()
783
791
self .js_socket_path_prefix = js_socket_path_prefix
@@ -1384,8 +1392,32 @@ async def on_message(self, msg):
1384
1392
if msg_type == "pong" :
1385
1393
if self .ping_start is None : logger_webrtc_input .warning ("received pong before ping" ); return
1386
1394
self .on_ping_response (float ("%.3f" % ((time .time () - self .ping_start ) / 2 * 1000 )))
1387
- elif msg_type == "kd" : await self .send_x11_keypress (int (toks [1 ]), down = True )
1388
- elif msg_type == "ku" : await self .send_x11_keypress (int (toks [1 ]), down = False )
1395
+ elif msg_type == "kd" :
1396
+ keysym = int (toks [1 ])
1397
+ is_printable = (0x20 <= keysym <= 0xFF ) or ((keysym & 0xFF000000 ) == 0x01000000 )
1398
+ if keysym in self .MODIFIER_KEYSYMS :
1399
+ self .active_modifiers .add (keysym )
1400
+ if is_printable and not self .active_modifiers :
1401
+ unicode_codepoint = keysym & 0x00FFFFFF if (keysym & 0xFF000000 ) == 0x01000000 else keysym
1402
+ try :
1403
+ char_to_type = chr (unicode_codepoint )
1404
+ logger_webrtc_input .debug (f"No modifiers active. Using atomic 'type' for '{ char_to_type } '." )
1405
+ await self .on_message (f"co,end,{ char_to_type } " )
1406
+ except (ValueError , TypeError ):
1407
+ await self .send_x11_keypress (keysym , down = True )
1408
+ else :
1409
+ await self .send_x11_keypress (keysym , down = True )
1410
+ elif msg_type == "ku" :
1411
+ keysym = int (toks [1 ])
1412
+ was_modifier_active = bool (self .active_modifiers )
1413
+ is_modifier_key = keysym in self .MODIFIER_KEYSYMS
1414
+ if is_modifier_key :
1415
+ self .active_modifiers .discard (keysym )
1416
+ is_printable = (0x20 <= keysym <= 0xFF ) or ((keysym & 0xFF000000 ) == 0x01000000 )
1417
+ if is_printable and not was_modifier_active :
1418
+ pass
1419
+ else :
1420
+ await self .send_x11_keypress (keysym , down = False )
1389
1421
elif msg_type == "kr" : await self .reset_keyboard ()
1390
1422
elif msg_type in ["m" , "m2" ]:
1391
1423
relative = msg_type == "m2"
0 commit comments