I'm using
a part of this code to disable hotkeys.
But even after 2 days of lurking around the web, I haven't found a solution for the error 1401 which doesn't disable ALT+TAB, I would ignore this if I could and just put the line of code for ALT+TAB in comentary, but I realy need it to be disabled since I'm running a cybercafe based application.
Using:
using System.Diagnostics;
using System.Runtime.InteropServices;
DLL Library:
#region Dynamic Link Library Imports
[DllImport("user32.dll")]
private static extern int FindWindow(string cls, string wndwText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int cmd);
[DllImport("user32.dll")]
private static extern long SHAppBarMessage(long dword, int cmd);
[DllImport("user32.dll")]
private static extern int RegisterHotKey(IntPtr hwnd, int id, int
fsModifiers, int vk);
[DllImport("user32.dll")]
private static extern int UnregisterHotKey(IntPtr hwnd, int id);
#endregion
Constants and Variables:
#region Modifier Constants and Variables
private const int USE_ALT = 1;
private const int USE_CTRL = 2;
private const int USE_SHIFT = 4;
private const int USE_WIN = 8;
short mHotKeyId = 0;
#endregion
MainCode to block the hotkeys:
#region
private void buttonlock()
{
RegisterGlobalHotKey(Keys.F4, USE_ALT);
RegisterGlobalHotKey(Keys.W, USE_CTRL);
RegisterGlobalHotKey(Keys.N, USE_CTRL);
RegisterGlobalHotKey(Keys.S, USE_CTRL);
RegisterGlobalHotKey(Keys.A, USE_CTRL);
RegisterGlobalHotKey(Keys.C, USE_CTRL);
RegisterGlobalHotKey(Keys.X, USE_CTRL);
RegisterGlobalHotKey(Keys.V, USE_CTRL);
RegisterGlobalHotKey(Keys.B, USE_CTRL);
RegisterGlobalHotKey(Keys.F, USE_CTRL);
RegisterGlobalHotKey(Keys.H, USE_CTRL);
RegisterGlobalHotKey(Keys.Tab, USE_ALT);
ShowWindow(FindWindow("Shell_TrayWnd", null), 0);
}
private void RegisterGlobalHotKey(Keys hotkey, int modifiers)
{
try
{
mHotKeyId++;
if (mHotKeyId > 0)
{
if (RegisterHotKey(this.Handle, mHotKeyId, modifiers,
Convert.ToInt16(hotkey)) == 0)
{
MessageBox.Show("Error: " +
mHotKeyId.ToString() + " - " +
Marshal.GetLastWin32Error().ToString(),
"Hot Key Registration");
}
}
}
catch
{
UnregisterGlobalHotKey();
}
}
private void UnregisterGlobalHotKey()
{
for (int i = 0; i < mHotKeyId; i++)
{
UnregisterHotKey(this.Handle, i);
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
const int WM_HOTKEY = 0x312;
if (m.Msg == WM_HOTKEY)
{
}
}
#endregion