[英]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.