2

我们有一个硬件返回按钮执行某个动作的情况,但是这个动作也会在使用 SIP 控件上的返回按钮时触发。

无论如何确定 KeyPressEventArg 是否来自 SIP?

    /// <summary>
    /// Handles the Enter button being pressed as navigation to complete the signature capture
    /// </summary>
    /// <param name="e">The key event args to quaify what button was pressed.</param>
    public override void HandleKeyPress(KeyPressEventArgs e)
    {
        if (e.KeyChar == '\r') // and is not SIP '\r'
        {
            // need to handle only hard button not SIP
        }
    }

非常感谢您对此的任何启发

4

2 回答 2

2

好的,找到了一种方法来做到这一点,但是我觉得这可能并不适用于所有设备类型。

        public void WndProc(ref Microsoft.WindowsCE.Forms.Message m)
        {
            if (m.Msg == WM_KEYDOWN && (m.WParam == (IntPtr)VK_RETURN && m.LParam != (IntPtr)1))
            {
                 //Handle hard button
            }
        }

LParam当来自 SIP 时,按键的似乎始终为“1”。我将继续在我们所有的设备类型上进行测试

如果有人对此有更好的方法,请在下面发布:)

于 2012-12-10T02:40:29.723 回答
2

好的,经过一天的试验,我找到了一种稳定的方法来指示硬按钮按键的 SIP(​​InputPanel)按键。

使用PeekMessage我们可以检查消息队列中的键值并检查LParam来自 SIP(​​跨所有设备)时似乎总是为 1 的“1”。

下面的代码

public class InputHelper
{
    #region Static Members

    /// <summary>
    /// Determines whether the key value pressed originated from the SIP
    /// </summary>
    /// <param name="keyValue">The key value.</param>
    /// <param name="handle">The widget handle.</param>
    /// <returns>
    ///   <c>true</c> if is sip key press; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsSipKeyPress(int keyValue, IntPtr handle)
    {
        NativeMessage m;
        if (PeekMessage(out m, handle, 0, 0, PM_NOREMOVE))
        {
            // All SIP inputs have LParam of 1, so ignore these
            if (m.msg == WM_CHAR && m.wParam == (IntPtr)keyValue && m.lParam == (IntPtr)1)
            {
                return true;
            }
        }
        return false;
    }

    #endregion


    #region P-Invoke

    const uint PM_NOREMOVE = 0x0000;
    const uint WM_CHAR = 258;

    [DllImport("coredll.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool PeekMessage(out NativeMessage lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);

    [StructLayout(LayoutKind.Sequential)]
    public struct NativeMessage
    {
        public IntPtr handle;
        public uint msg;
        public IntPtr wParam;
        public IntPtr lParam;
        public uint time;
        public System.Drawing.Point p;
    }

    #endregion
}

用法:

/// <summary>
/// Handle a KeyDown event and check for Hardbutton Return key
/// </summary>
/// <param name="e">A KeyEventArgs instance</param>
public override void HandleKeyDown(KeyEventArgs e)
{
    if (e.KeyValue == 13)
    {
        if (!InputHelper.IsSipKeyPress(13, base.Handle))
        {
            CompleteProcess();
        }
    }
    base.HandleKeyDown(e);
}  

希望这对其他人有帮助:)

于 2012-12-11T04:20:28.290 回答