Fix track posture hotkey bug on windows.

The change track posture hotkey '/' was getting interpreted as the show
hotkey list shortcut '?' on windows.  This fix is temporary hack to fix
the problem which much more involved than the simple #ifdef/#endif used
to fix this issue.

Add key code tracing to help analyze key codes for future development.
This commit is contained in:
Wayne Stambaugh 2018-03-30 13:32:53 -04:00
parent d391489596
commit 53b1ec8146
4 changed files with 77 additions and 5 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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();

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 2007 Wayne Stambaugh <stambaughw@gmail.com>
* 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;

View File

@ -36,6 +36,11 @@
#include <core/optional.h>
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

View File

@ -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 <stambaughw@verizon.net>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* 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: