如何禁用 Motorola MC75 上的发送键和结束键

发布于 2024-10-21 19:23:36 字数 67 浏览 1 评论 0 原文

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

我需要任何 C# 示例代码,

提前致谢

How to Disable the Send and End keys on Motorola MC75 ?

i need any C# sample code for this

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云淡月浅 2024-10-28 19:23:36

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

Use Motorola AppCenter to restrict running applications. It allows you to block keys, programs, etc.

十级心震 2024-10-28 19:23:36

编辑:我之前不知道 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) 来取消挂钩。

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

Edit: I didn't know about the "AllKeys" solution posted by PaulH before, that should be a better solution than the one i posted.

Im assuming that you want to handle the green and red hardware keys? The call and hangup keys?

If that is the case you can monitor the keyevents and choose to not pass them on to windows if they match your criteria.

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

This is a quick and dirty solution that you might wanna clean up before use :)
Just call HookKeyboardEvent(true) to enable the hook and HookKeyboardEvent(false) to unhook.

I hope it solves your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文