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
I answered this on the MSDN forums.
You can use the AllKeys API to do this.
The P/Invoke signature for using it in C# is here: http://blogs.msdn.com/b/mikefrancis/archive/2009/03/28/porting-gapi-keys-to-wm-6-1-and-6-5.aspx
A good general explanation of its usage is here: http://windowsteamblog.com/windows_phone/b/windowsphone/archive/2009/07/14/just-say-no-to-gapi-what-you-need-to-know-about-allkeys-and-input-management.aspx
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.
精彩评论