*/
#define CEC_BUTTON_TIMEOUT 500
+/*!
+ * don't send the same key twice within this timeout in milliseconds
+ */
+#define CEC_DOUBLE_TAP_TIMEOUT_MS 200
+
/*!
* don't query the power state for the same device within this timeout in milliseconds
*/
m_bRegistered(false),
m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
m_buttontime(0),
- m_iPreventForwardingPowerOffCommand(0)
+ m_iPreventForwardingPowerOffCommand(0),
+ m_iLastKeypressTime(0)
{
+ m_lastKeypress.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
+ m_lastKeypress.duration = 0;
m_configuration.Clear();
// set the initial configuration
SetConfiguration(configuration);
{
CLockObject lock(m_cbMutex);
if (m_configuration.callbacks && m_configuration.callbacks->CBCecKeyPress)
- m_configuration.callbacks->CBCecKeyPress(m_configuration.callbackParam, key);
+ {
+ // prevent double taps
+ int64_t now = GetTimeMs();
+ if (m_lastKeypress.keycode != key.keycode ||
+ key.duration > 0 ||
+ now - m_iLastKeypressTime >= CEC_DOUBLE_TAP_TIMEOUT_MS)
+ {
+ // no double tap
+ if (key.duration == 0)
+ m_iLastKeypressTime = now;
+ m_lastKeypress = key;
+ m_configuration.callbacks->CBCecKeyPress(m_configuration.callbackParam, key);
+ }
+ }
}
void CCECClient::CallbackAddLog(const cec_log_message &message)
cec_user_control_code m_iCurrentButton; /**< the control code of the button that's currently held down (if any) */
int64_t m_buttontime; /**< the timestamp when the button was pressed (in seconds since epoch), or 0 if none was pressed. */
int64_t m_iPreventForwardingPowerOffCommand; /**< prevent forwarding standby commands until this time */
+ int64_t m_iLastKeypressTime; /**< last time a key press was sent to the client */
+ cec_keypress m_lastKeypress; /**< the last key press that was sent to the client */
};
}