diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 03c53bfcd7..6211c5ab6a 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -234,6 +234,7 @@ EDA_DRAW_FRAME::~EDA_DRAW_FRAME() void EDA_DRAW_FRAME::OnCharHook( wxKeyEvent& event ) { + wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_FRAME::OnCharHook %s", dumpKeyEvent( event ) ); // Key events can be filtered here. // Currently no filtering is made. event.Skip(); diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp index 104e373b18..2ef82b8f35 100644 --- a/common/draw_panel.cpp +++ b/common/draw_panel.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr * Copyright (C) 2007 Wayne Stambaugh - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -73,6 +73,14 @@ static const int CURSOR_SIZE = 12; ///< Cursor size in pixels static const wxString kicadTraceCoords = wxT( "KICAD_TRACE_COORDS" ); +/** + * @ingroup trace_env_vars + * + * Flag to enable wxKeyEvent debug tracing. + */ +const wxString kicadTraceKeyEvent = "KICAD_KEY_EVENTS"; + + // Events used by EDA_DRAW_PANEL BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow ) EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving ) @@ -83,7 +91,7 @@ BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow ) #endif EVT_MOUSE_EVENTS( EDA_DRAW_PANEL::OnMouseEvent ) EVT_CHAR( EDA_DRAW_PANEL::OnKeyEvent ) - EVT_CHAR_HOOK( EDA_DRAW_PANEL::OnCharHook ) + EVT_CHAR_HOOK( EDA_DRAW_PANEL::OnKeyEvent ) EVT_PAINT( EDA_DRAW_PANEL::OnPaint ) EVT_ERASE_BACKGROUND( EDA_DRAW_PANEL::OnEraseBackground ) EVT_SCROLLWIN( EDA_DRAW_PANEL::OnScroll ) @@ -1387,8 +1395,29 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) } +// @todo Move this to a debug helper file in common folder. +wxString dumpKeyEvent( const wxKeyEvent& aEvent ) +{ + wxString dump = wxString::Format( "key code %d", aEvent.GetKeyCode() ); + + if( aEvent.GetUnicodeKey() ) + dump += wxString::Format(", unicode key %d", aEvent.GetUnicodeKey() ); + if( aEvent.HasModifiers() ) + dump += wxString::Format( ", mod %d", aEvent.GetModifiers() ); + if( aEvent.ShiftDown() ) + dump += ", shift"; + if( aEvent.ControlDown() ) + dump += ", ctrl"; + if( aEvent.AltDown() ) + dump += ", alt"; + + return dump; +} + + void EDA_DRAW_PANEL::OnCharHook( wxKeyEvent& event ) { + wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_PANEL::OnCharHook %s", dumpKeyEvent( event ) ); event.Skip(); } @@ -1398,6 +1427,8 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) int localkey; wxPoint pos; + wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_PANEL::OnKeyEvent %s", dumpKeyEvent( event ) ); + localkey = event.GetKeyCode(); switch( localkey ) @@ -1434,6 +1465,13 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) if( event.ShiftDown() && ( keyIsLetter || localkey > 256 ) ) localkey |= GR_KB_SHIFT; + // For some reason on windows with US keyboards, the /? key always returns the '/' key code + // where as the <,, .>, ;:, '", [{, ]}, and \| keys return the shifted character key code. +#if defined( __WXMSW__ ) + if( event.ShiftDown() && localkey == '/' ) + localkey = '?'; +#endif + if( event.ControlDown() ) localkey |= GR_KB_CTRL; diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 26087b1026..1773d06622 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -36,6 +36,11 @@ #include +extern wxString dumpKeyEvent( const wxKeyEvent& aEvent ); + +extern const wxString kicadTraceKeyEvent; + + ///> Stores information about a mouse button state struct TOOL_DISPATCHER::BUTTON_STATE { @@ -374,12 +379,21 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) { if( !keyIsSpecial ) { + wxLogTrace( kicadTraceKeyEvent, + "TOOL_DISPATCHER::DispatchWxEvent wxEVT_CHAR_HOOK %s", + dumpKeyEvent( *ke ) ); aEvent.Skip(); return; } else key = translateSpecialCode( key ); } + else + { + wxLogTrace( kicadTraceKeyEvent, + "TOOL_DISPATCHER::DispatchWxEvent wxEVT_CHAR %s", + dumpKeyEvent( *ke ) ); + } int mods = decodeModifiers( ke ); @@ -396,6 +410,14 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) key += 'A' - 1; } + // For some reason on windows with US keyboards, the /? key always returns the '/' key + // code where as the <,, .>, ;:, '", [{, ]}, and \| keys return the shifted character + // key code. +#if defined( __WXMSW__ ) + if( ( mods & MD_SHIFT ) && ( key == '?' ) ) + mods &= ~MD_SHIFT; +#endif + if( key == WXK_ESCAPE ) // ESC is the special key for cancelling tools evt = TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL ); else diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index c8f9a3ef8b..c8c9968649 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -52,6 +52,17 @@ typedef void ( *MOUSE_CAPTURE_CALLBACK )( EDA_DRAW_PANEL* aPanel, wxDC* aDC, typedef void ( *END_MOUSE_CAPTURE_CALLBACK )( EDA_DRAW_PANEL* aPanel, wxDC* aDC ); +/** + * Debug helper for printing wxKeyEvent information. + * + * @param aEvent is the wxKeyEvent to generate the print string from. + * @return the wxKeyEvent information. + */ +extern wxString dumpKeyEvent( const wxKeyEvent& aEvent ); + +extern const wxString kicadTraceKeyEvent; + + class EDA_DRAW_PANEL : public wxScrolledWindow { private: