هاذا الكود حولته من VB.NET الي سي# ولكنه لم يعمل فهل من مساعدة ..
public class frmMain : System.Windows.Forms.Form
{
[System.Runtime.InteropServices.DllImport("user32", EntryPoint="SetWindowsHookExA")]
int SetWindowsHookEx(int idHook, LowLevelKeyboardProcDelegate lpfn, int hMod, int dwThreadId);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint="UnhookWindowsHookEx")]
int UnhookWindowsHookEx(int hHook);
delegate int LowLevelKeyboardProcDelegate(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint="CallNextHookEx")]
int CallNextHookEx(int hHook, int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);
struct KBDLLHOOKSTRUCT
{
int vkCode;
int scanCode;
int flags;
int time;
int dwExtraInfo;
}
int intLLKey;
public frmMain()
{
base.New();
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing) {
if (!(components == null)) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private System.ComponentModel.IContainer components;
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.lblInfo = new System.Windows.Forms.Label();
this.SuspendLayout();
this.lblInfo.Location = new System.Drawing.Point(16, 16);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(216, 88);
this.lblInfo.TabIndex = 0;
this.lblInfo.Text = "Alt-Tab, Alt-Esc, Ctrl-Esc, and the Windows key are disabled. Ctrl-Alt-Del and Al" + "t-F4 are still enabled. Close the application to reset the keyboard. While this " + "program is running, the low-level keyboard effect is global.";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(248, 118);
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.lblInfo});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "LowLevel Keyboard Hook";
this.ResumeLayout(false);
}
private void frmMain_Load(object sender, System.EventArgs e)
{
intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, /* might be wrong, please check */ new EventHandler(LowLevelKeyboardProc), System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32(), 0);
}
private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
UnhookWindowsHookEx(intLLKey);
}
private int LowLevelKeyboardProc(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam)
{
bool blnEat = false;
if (wParam == 256 || wParam == 257 || wParam == 260 || wParam == 261) {
blnEat = ((lParam.vkCode == 9) && (lParam.flags == 32)) | ((lParam.vkCode == 27) && (lParam.flags == 32)) | ((lParam.vkCode == 27) && (lParam.flags == 0)) | ((lParam.vkCode == 91) && (lParam.flags == 1)) | ((lParam.vkCode == 92) && (lParam.flags == 1));
}
if (blnEat == true) {
return 1;
} else {
return CallNextHookEx(0, nCode, wParam, lParam);
}
}
internal System.Windows.Forms.Label lblInfo;
}