[英]How to Disable the Send and End keys on Motorola MC75
如何在Motorola MC75上禁用发送键和结束键?
我需要任何C#示例代码
提前致谢
我在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-知道-约-allkeys和输入,management.aspx
使用Motorola AppCenter限制正在运行的应用程序。 它允许您阻止键,程序等。
编辑:我之前不知道PaulH发布的“ AllKeys”解决方案,这应该比我发布的解决方案更好。
我假设您要处理绿色和红色硬件键? 通话和挂断键?
在这种情况下,您可以监视按键事件,并选择在它们符合您的条件时不将其传递给Windows。
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)。
我希望它能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.