← Back to team overview

kicad-developers team mailing list archive

Modifier keys for hotkeys

 

Hi,

I'm trying to get a hotkey defined as "Ctrl-Shift-D". Currently, I can
make it work easily in GAL mode, but not in the legacy mode.

This seems to be because of the following code in draw_panel.cpp:

    if( event.ShiftDown() && (event.GetKeyCode() > 256) )
        localkey |= GR_KB_SHIFT;

    /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
     * They have an ascii code from 1 to 27 remapped
     * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
     */
    if( (localkey > GR_KB_CTRL) && (localkey <= GR_KB_CTRL+26) )
        localkey += 'A' - 1;

The first check will refuse to set the shift modifier unless the keycode
is more than 256 (so all normal letters fail this).

Secondly, the localkey is not remapped for cases other than Ctrl-<X>.
(e.g. Ctrl-Shift-<X>).

I changed it to the following:

    if( event.ShiftDown() )
        localkey |= GR_KB_SHIFT;

    /* ... */
    if( ( localkey & ~( GR_KB_CTRL | GR_KB_SHIFT | GR_KB_ALT ) ) <= 26 )
        localkey += 'A' - 1;

And the hotkey now works. Ctrl-D still works, as do the other hotkeys.
Does anyone know why these two checks were made like this, and if this
change is valid to make? I have attached a patch of the change.

This was all on Linux, in case there is some platform-dependent
behaviour here.

Cheers,

John
diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp
index 919fdb1..247346c 100644
--- a/common/draw_panel.cpp
+++ b/common/draw_panel.cpp
@@ -1370,14 +1370,15 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
         localkey |= GR_KB_CTRL;
     if( event.AltDown() )
         localkey |= GR_KB_ALT;
-    if( event.ShiftDown() && (event.GetKeyCode() > 256) )
+    if( event.ShiftDown() )
         localkey |= GR_KB_SHIFT;
 
     /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
+     * (or Ctrl-Shift, Ctrl-Alt, etc)
      * They have an ascii code from 1 to 27 remapped
      * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
      */
-    if( (localkey > GR_KB_CTRL) && (localkey <= GR_KB_CTRL+26) )
+    if( ( localkey & ~( GR_KB_CTRL | GR_KB_SHIFT | GR_KB_ALT ) ) <= 26 )
         localkey += 'A' - 1;
 
     INSTALL_UNBUFFERED_DC( DC, this );

Follow ups