@@ -276,7 +276,6 @@ impl LayoutCache {
276276
277277 pub fn get_mods ( & mut self ) -> Modifiers {
278278 let ( _, layout) = self . get_current_layout ( ) ;
279- let filter_out_altgr = layout. has_alt_graph && key_pressed ( VK_RMENU ) ;
280279 let mut state = ModifiersState :: empty ( ) ;
281280 let mut pressed_mods = ModifiersKeys :: empty ( ) ;
282281
@@ -290,21 +289,29 @@ impl LayoutCache {
290289 state. contains ( ModifiersState :: SHIFT ) && key_pressed ( VK_RSHIFT ) ,
291290 ) ;
292291
293- pressed_mods. set ( ModifiersKeys :: LCONTROL , key_pressed ( VK_LCONTROL ) && !filter_out_altgr) ;
294- pressed_mods. set ( ModifiersKeys :: RCONTROL , key_pressed ( VK_RCONTROL ) && !filter_out_altgr) ;
295- state. set (
296- ModifiersState :: CONTROL ,
297- pressed_mods. contains ( ModifiersKeys :: LCONTROL )
298- || pressed_mods. contains ( ModifiersKeys :: RCONTROL ) ,
299- ) ;
300-
301- pressed_mods. set ( ModifiersKeys :: LALT , key_pressed ( VK_LMENU ) && !filter_out_altgr) ;
302- pressed_mods. set ( ModifiersKeys :: RALT , key_pressed ( VK_RMENU ) && !filter_out_altgr) ;
292+ pressed_mods. set ( ModifiersKeys :: LALT , key_pressed ( VK_LMENU ) ) ;
293+ let is_ralt = key_pressed ( VK_RMENU ) ;
294+ let is_altgr = layout. has_alt_graph && is_ralt;
295+ pressed_mods. set ( ModifiersKeys :: RALT , is_ralt && !is_altgr) ;
303296 state. set (
304297 ModifiersState :: ALT ,
305298 pressed_mods. contains ( ModifiersKeys :: LALT )
306299 || pressed_mods. contains ( ModifiersKeys :: RALT ) ,
307300 ) ;
301+ state. set ( ModifiersState :: ALTGR , is_altgr) ;
302+
303+ // On Windows AltGr = RAlt + LCtrl, and OS sends artificial LCtrl key event, which needs to
304+ // be filtered out without touching "real" LCtrl events to allow separate bindings of
305+ // LCtrl+AltGr+X and AltGr+X. TODO: this is likely only possible by tracking the
306+ // physical LCtrl state via raw keyboard events as the message loop isn't capable of
307+ // excluding artificial LCtrl events?
308+ pressed_mods. set ( ModifiersKeys :: RCONTROL , key_pressed ( VK_RCONTROL ) ) ;
309+ pressed_mods. set ( ModifiersKeys :: LCONTROL , key_pressed ( VK_LCONTROL ) && !is_altgr) ;
310+ state. set (
311+ ModifiersState :: CONTROL ,
312+ pressed_mods. contains ( ModifiersKeys :: LCONTROL )
313+ || pressed_mods. contains ( ModifiersKeys :: RCONTROL ) ,
314+ ) ;
308315
309316 pressed_mods. set ( ModifiersKeys :: LMETA , key_pressed ( VK_LWIN ) ) ;
310317 pressed_mods. set ( ModifiersKeys :: RMETA , key_pressed ( VK_RWIN ) ) ;
0 commit comments