Add wxKeyEvent::IsAutoRepeat()
The new method is currently supported in Qt, Cocoa, MSW ports (i.e. all major ones except for wxGTK). Keyboard example updated with a "Repeat" column. Closes https://github.com/wxWidgets/wxWidgets/pull/2414
This commit is contained in:
		
				
					committed by
					
						
						Vadim Zeitlin
					
				
			
			
				
	
			
			
			
						parent
						
							a37629b035
						
					
				
				
					commit
					a052557af3
				
			@@ -2218,6 +2218,9 @@ public:
 | 
				
			|||||||
    // get the raw key flags (platform-dependent)
 | 
					    // get the raw key flags (platform-dependent)
 | 
				
			||||||
    wxUint32 GetRawKeyFlags() const { return m_rawFlags; }
 | 
					    wxUint32 GetRawKeyFlags() const { return m_rawFlags; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // returns true if this is a key auto repeat event
 | 
				
			||||||
 | 
					    bool IsAutoRepeat() const { return m_isRepeat; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Find the position of the event
 | 
					    // Find the position of the event
 | 
				
			||||||
    void GetPosition(wxCoord *xpos, wxCoord *ypos) const
 | 
					    void GetPosition(wxCoord *xpos, wxCoord *ypos) const
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -2279,6 +2282,9 @@ public:
 | 
				
			|||||||
    wxUint32      m_rawCode;
 | 
					    wxUint32      m_rawCode;
 | 
				
			||||||
    wxUint32      m_rawFlags;
 | 
					    wxUint32      m_rawFlags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Indicates whether the key event is a repeat
 | 
				
			||||||
 | 
					    bool          m_isRepeat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    // Set the event to propagate if necessary, i.e. if it's of wxEVT_CHAR_HOOK
 | 
					    // Set the event to propagate if necessary, i.e. if it's of wxEVT_CHAR_HOOK
 | 
				
			||||||
    // type. This is used by all ctors.
 | 
					    // type. This is used by all ctors.
 | 
				
			||||||
@@ -2305,6 +2311,7 @@ private:
 | 
				
			|||||||
#if wxUSE_UNICODE
 | 
					#if wxUSE_UNICODE
 | 
				
			||||||
        m_uniChar = evt.m_uniChar;
 | 
					        m_uniChar = evt.m_uniChar;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					        m_isRepeat = evt.m_isRepeat;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Initialize m_x and m_y using the current mouse cursor position if
 | 
					    // Initialize m_x and m_y using the current mouse cursor position if
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1547,6 +1547,15 @@ public:
 | 
				
			|||||||
    */
 | 
					    */
 | 
				
			||||||
    bool IsKeyInCategory(int category) const;
 | 
					    bool IsKeyInCategory(int category) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					        Returns true if this event is an auto-repeat of the key, false if this
 | 
				
			||||||
 | 
					        is the initial key press.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @since 3.1.6
 | 
				
			||||||
 | 
					        @onlyfor{wxosx,wxmsw,wxQt}
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    bool IsAutoRepeat() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //@{
 | 
					    //@{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
        Obtains the position (in client coordinates) at which the key was pressed.
 | 
					        Obtains the position (in client coordinates) at which the key was pressed.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -235,7 +235,7 @@ MyFrame::MyFrame(const wxString& title)
 | 
				
			|||||||
                                            wxTE_READONLY);
 | 
					                                            wxTE_READONLY);
 | 
				
			||||||
    headerText->SetValue(
 | 
					    headerText->SetValue(
 | 
				
			||||||
               " event          key     KeyCode mod   UnicodeKey  "
 | 
					               " event          key     KeyCode mod   UnicodeKey  "
 | 
				
			||||||
               "  RawKeyCode RawKeyFlags  Position");
 | 
					               "  RawKeyCode RawKeyFlags  Position      Repeat");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_logText = new wxTextCtrl(this, wxID_ANY, "",
 | 
					    m_logText = new wxTextCtrl(this, wxID_ANY, "",
 | 
				
			||||||
@@ -538,6 +538,7 @@ void MyFrame::LogEvent(const wxString& name, wxKeyEvent& event)
 | 
				
			|||||||
                   "  not-set    not-set"
 | 
					                   "  not-set    not-set"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
                   "  (%5d,%5d)"
 | 
					                   "  (%5d,%5d)"
 | 
				
			||||||
 | 
					                   "  %s"
 | 
				
			||||||
                   "\n",
 | 
					                   "\n",
 | 
				
			||||||
               name,
 | 
					               name,
 | 
				
			||||||
               GetKeyName(event),
 | 
					               GetKeyName(event),
 | 
				
			||||||
@@ -556,6 +557,7 @@ void MyFrame::LogEvent(const wxString& name, wxKeyEvent& event)
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
               , event.GetX()
 | 
					               , event.GetX()
 | 
				
			||||||
               , event.GetY()
 | 
					               , event.GetY()
 | 
				
			||||||
 | 
					               , event.IsAutoRepeat() ? "Yes" : "No"
 | 
				
			||||||
               );
 | 
					               );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_logText->AppendText(msg);
 | 
					    m_logText->AppendText(msg);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6303,6 +6303,8 @@ MSWInitAnyKeyEvent(wxKeyEvent& event,
 | 
				
			|||||||
    event.m_rawCode = (wxUint32) wParam;
 | 
					    event.m_rawCode = (wxUint32) wParam;
 | 
				
			||||||
    event.m_rawFlags = (wxUint32) lParam;
 | 
					    event.m_rawFlags = (wxUint32) lParam;
 | 
				
			||||||
    event.SetTimestamp(::GetMessageTime());
 | 
					    event.SetTimestamp(::GetMessageTime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    event.m_isRepeat = (HIWORD(lParam) & KF_REPEAT) == KF_REPEAT;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // anonymous namespace
 | 
					} // anonymous namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -452,6 +452,7 @@ void wxWidgetCocoaImpl::SetupKeyEvent(wxKeyEvent &wxevent , NSEvent * nsEvent, N
 | 
				
			|||||||
    wxevent.m_rawFlags = modifiers;
 | 
					    wxevent.m_rawFlags = modifiers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wxevent.SetTimestamp( (int)([nsEvent timestamp] * 1000) ) ;
 | 
					    wxevent.SetTimestamp( (int)([nsEvent timestamp] * 1000) ) ;
 | 
				
			||||||
 | 
					    wxevent.m_isRepeat = (eventType == NSKeyDown) && [nsEvent isARepeat];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wxString chars;
 | 
					    wxString chars;
 | 
				
			||||||
    if ( eventType != NSFlagsChanged )
 | 
					    if ( eventType != NSFlagsChanged )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1390,6 +1390,7 @@ bool wxWindowQt::QtHandleKeyEvent ( QWidget *WXUNUSED( handler ), QKeyEvent *eve
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    e.m_rawCode = event->nativeVirtualKey();
 | 
					    e.m_rawCode = event->nativeVirtualKey();
 | 
				
			||||||
    e.m_rawFlags = event->nativeModifiers();
 | 
					    e.m_rawFlags = event->nativeModifiers();
 | 
				
			||||||
 | 
					    e.m_isRepeat = event->isAutoRepeat();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Modifiers
 | 
					    // Modifiers
 | 
				
			||||||
    wxQtFillKeyboardModifiers( event->modifiers(), &e );
 | 
					    wxQtFillKeyboardModifiers( event->modifiers(), &e );
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user