简体   繁体   中英

How to Disable the Send and End keys on Motorola MC75

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

i need any C# sample code for this

thanks in advance

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM