0

如何禁用摩托罗拉 MC75 上的发送和结束键?

我需要任何 C# 示例代码

提前致谢

4

3 回答 3

4

我在MSDN 论坛上回答了这个问题。

您可以使用 AllKeys API 来执行此操作。

在 C# 中使用它的 P/Invoke 签名在这里:http: //blogs.msdn.com/b/mikefrancis/archive/2009/03/28/porting-gapi-keys-to-wm-6-1-and -6-5.aspx

对其用法的一个很好的一般解释是:http: //windowsteamblog.com/windows_phone/b/windowsphone/archive/2009/07/14/just-say-no-to-gapi-what-you-need-to-了解所有键和输入管理.aspx

于 2011-03-16T15:40:19.707 回答
1

使用 Motorola AppCenter 限制正在运行的应用程序。它允许您阻止密钥、程序等。

于 2012-07-24T15:49:56.583 回答
0

编辑:我之前不知道 PaulH 发布的“AllKeys”解决方案,这应该是比我发布的更好的解决方案。

我假设您要处理绿色和红色硬件键?通话键和挂机键?

如果是这种情况,您可以监视键事件并在它们符合您的条件时选择不将它们传递到窗口。

private const int WH_KEYBOARD_LL = 20;
private static int _hookHandle;
private HookProc _hookDelegate;

[DllImport("coredll.dll")]
private static extern int SetWindowsHookEx(int type, HookProc hookProc, IntPtr       hInstance, int m);

[DllImport("coredll.dll")]
private static extern IntPtr GetModuleHandle(string mod);

[DllImport("coredll.dll", SetLastError = true)]
private static extern int UnhookWindowsHookEx(int idHook);

[DllImport("coredll.dll")]
private static extern int CallNextHookEx(HookProc hhk, int nCode, IntPtr wParam, IntPtr lParam);


private bool HookKeyboardEvent(bool action)
{
try
{
    if (action)
    {
        HookKeyboardEvent(false);

        _hookDelegate = new HookProc(HookProcedure);
        _hookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, _hookDelegate, GetModuleHandle(null), 0);

        if (_hookHandle == 0)
        {
            return false;
        }
        return true;
    }
    if (_hookHandle != 0)
    {
        //Unhook the previouse one
        UnhookWindowsHookEx(_hookHandle);
        return true;
    }
    return false;
}
catch (Exception ex)
{
    string dump = ex.Message;
    return false;
}
}

private int HookProcedure(int code, IntPtr wParam, IntPtr lParam)
{
try
{
    var hookStruct = (KBDLLHOOKSTRUCT) Marshal.PtrToStructure(lParam, typeof (KBDLLHOOKSTRUCT));
    if (DoHardwareKeyPress(hookStruct.vkCode, hookStruct.scanCode, wParam.ToInt32()))
        return CallNextHookEx(_hookDelegate, code, wParam, lParam);
    else
        return -1;
}
catch (Exception ex)
{
    string dump = ex.Message;
    return -1;
}
}

private bool DoHardwareKeyPress(int softKey, int hardKey, int keyState)
{
try
{
    string keyPressInformation = string.Format("SoftKey = {0}, HardKey = {1}, KeyState = {2}", softKey, hardKey,
                                               keyState);
    if (softKey == 114 && hardKey == 4 && (keyState == 256 || keyState == 257))
        return false;
    else if (softKey == 115 && hardKey == 12 && (keyState == 256 || keyState == 257))
        return false;
    else
        return true;
}
catch (Exception ex)
{
    string dump = ex.Message;
    return true;
}
}

#region Nested type: HookProc

internal delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);

#endregion

#region Nested type: KBDLLHOOKSTRUCT

private struct KBDLLHOOKSTRUCT
{
public IntPtr dwExtraInfo;
public int flags;
public int scanCode;
public int time;
public int vkCode;
}

#endregion

这是一个快速而肮脏的解决方案,您可能想在使用前清理它:) 只需调用 HookKeyboardEvent(true) 以启用挂钩并 HookKeyboardEvent(false) 取消挂钩。

我希望它能解决你的问题。

于 2011-03-16T13:25:12.980 回答