@@ -273,16 +273,19 @@ def _event_mpl_coords(self, event):
273273 def motion_notify_event (self , event ):
274274 MouseEvent ("motion_notify_event" , self ,
275275 * self ._event_mpl_coords (event ),
276+ modifiers = self ._mpl_modifiers (event ),
276277 guiEvent = event )._process ()
277278
278279 def enter_notify_event (self , event ):
279280 LocationEvent ("figure_enter_event" , self ,
280281 * self ._event_mpl_coords (event ),
282+ modifiers = self ._mpl_modifiers (event ),
281283 guiEvent = event )._process ()
282284
283285 def leave_notify_event (self , event ):
284286 LocationEvent ("figure_leave_event" , self ,
285287 * self ._event_mpl_coords (event ),
288+ modifiers = self ._mpl_modifiers (event ),
286289 guiEvent = event )._process ()
287290
288291 def button_press_event (self , event , dblclick = False ):
@@ -294,6 +297,7 @@ def button_press_event(self, event, dblclick=False):
294297 num = {2 : 3 , 3 : 2 }.get (num , num )
295298 MouseEvent ("button_press_event" , self ,
296299 * self ._event_mpl_coords (event ), num , dblclick = dblclick ,
300+ modifiers = self ._mpl_modifiers (event ),
297301 guiEvent = event )._process ()
298302
299303 def button_dblclick_event (self , event ):
@@ -305,13 +309,15 @@ def button_release_event(self, event):
305309 num = {2 : 3 , 3 : 2 }.get (num , num )
306310 MouseEvent ("button_release_event" , self ,
307311 * self ._event_mpl_coords (event ), num ,
312+ modifiers = self ._mpl_modifiers (event ),
308313 guiEvent = event )._process ()
309314
310315 def scroll_event (self , event ):
311316 num = getattr (event , 'num' , None )
312317 step = 1 if num == 4 else - 1 if num == 5 else 0
313318 MouseEvent ("scroll_event" , self ,
314319 * self ._event_mpl_coords (event ), step = step ,
320+ modifiers = self ._mpl_modifiers (event ),
315321 guiEvent = event )._process ()
316322
317323 def scroll_event_windows (self , event ):
@@ -325,12 +331,10 @@ def scroll_event_windows(self, event):
325331 - self ._tkcanvas .canvasy (event .y_root - w .winfo_rooty ()))
326332 step = event .delta / 120
327333 MouseEvent ("scroll_event" , self ,
328- x , y , step = step , guiEvent = event )._process ()
329-
330- def _get_key (self , event ):
331- unikey = event .char
332- key = cbook ._unikey_or_keysym_to_mplkey (unikey , event .keysym )
334+ x , y , step = step , modifiers = self ._mpl_modifiers (event ),
335+ guiEvent = event )._process ()
333336
337+ def _mpl_modifiers (self , event , * , exclude = None ):
334338 # add modifier keys to the key string. Bit details originate from
335339 # http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
336340 # BIT_SHIFT = 0x001; BIT_CAPSLOCK = 0x002; BIT_CONTROL = 0x004;
@@ -339,32 +343,33 @@ def _get_key(self, event):
339343 # In general, the modifier key is excluded from the modifier flag,
340344 # however this is not the case on "darwin", so double check that
341345 # we aren't adding repeat modifier flags to a modifier key.
342- if sys . platform == 'win32' :
343- modifiers = [( 2 , 'ctrl' , ' control' ),
344- ( 17 , 'alt' , ' alt' ),
345- ( 0 , 'shift' , ' shift' ),
346- ]
347- elif sys . platform == 'darwin' :
348- modifiers = [( 2 , 'ctrl' , 'control' ),
349- ( 4 , 'alt' , 'alt' ),
350- ( 0 , 'shift' , 'shift' ),
351- ( 3 , 'super' , 'super' ),
352- ]
353- else :
354- modifiers = [( 2 , 'ctrl' , 'control' ),
355- ( 3 , 'alt' , 'alt' ),
356- ( 0 , 'shift' , 'shift' ),
357- ( 6 , 'super' , 'super' ),
358- ]
346+ modifiers = [
347+ ( "ctrl" , 2 , " control" ),
348+ ( "alt" , 17 , " alt" ),
349+ ( "shift" , 0 , " shift" ),
350+ ] if sys . platform == "win32" else [
351+ ( "ctrl" , 2 , "control" ),
352+ ( "alt" , 4 , "alt" ),
353+ ( "shift" , 0 , "shift" ),
354+ ( "super" , 3 , "super" ),
355+ ] if sys . platform == "darwin" else [
356+ ( "ctrl" , 2 , "control" ),
357+ ( "alt" , 3 , "alt" ),
358+ ( "shift" , 0 , "shift" ),
359+ ( "super" , 6 , "super" ),
360+ ]
361+ return [ name for name , mod , key in modifiers
362+ if event . state & ( 1 << mod ) and exclude != key ]
359363
364+ def _get_key (self , event ):
365+ unikey = event .char
366+ key = cbook ._unikey_or_keysym_to_mplkey (unikey , event .keysym )
360367 if key is not None :
361- # shift is not added to the keys as this is already accounted for
362- for bitmask , prefix , key_name in modifiers :
363- if event .state & (1 << bitmask ) and key_name not in key :
364- if not (prefix == 'shift' and unikey ):
365- key = '{0}+{1}' .format (prefix , key )
366-
367- return key
368+ mods = self ._mpl_modifiers (event )
369+ # shift is not added to the keys as this is already accounted for.
370+ if "shift" in mods and unikey :
371+ mods .remove ("shift" )
372+ return "+" .join ([* mods , key ])
368373
369374 def key_press (self , event ):
370375 KeyEvent ("key_press_event" , self ,
0 commit comments