実験の別の日の後、私はハードボタンのキーの押下から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);
}
これが他の誰かに役立つことを願っています:)