string keyBuffer = string.Empty; Int32[,] Vkey = new Int32[2,150] void ReadfromKeyboard() { const uint MAPVK_VK_TO_VSC_EX = 0x04; const uint KLF_ACTIVATE = 0x00000001; for (int i=0; i<120; i++) { if( (Methods.GetAsyncKeyState(Vkey[1,i])== 1) || (Methods.GetAsyncKeyState(Vkey[1,i]) == Int16.MinValue))//Vkey is an array which store virtual key code like Vkey[1, 0] = 0x31; { uint temp =Methods.MapVirtualKeyEx((Convert.ToUInt32(Vkey[1,i])),MAPVK_VK_TO_VSC_EX,Methods.LoadKeyboardLayout(InputLanguage.CurrentInputLanguage.Culture.KeyboardLayoutId.ToString(),KLF_ACTIVATE)); StringBuilder keyname=new StringBuilder(); int nsize=50; if (Methods.GetKeyNameText(Convert.ToInt32(temp), keyname, nsize) != 0) { keyBuffer += keyname.ToString(); } } } if (keyBuffer != string.Empty) textBox1.Text=keyBuffer; }
YourWindowsFormClassName.KeyPreview = true;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)