Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone
I try to save user keystroke in each languages which is installed in the system. I use this code but it shows nothing, I searched a lot but unfortunately I didn't reach to any solution.
Please any one who can tell me what my problem is, help me out.
I'd appreciate any comment.
My code is as below:
C#
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;
            
  }
Posted
Updated 6-Jul-12 10:38am
v7
Comments
Sergey Alexandrovich Kryukov 6-Jul-12 12:19pm    
Please explain what's the problem.
--SA
a.fatemeh 6-Jul-12 12:23pm    
I really don't know what the problem is with my code but it doesn't show any thing in the TextBox which supposed to show each key which is press
ZurdoDev 6-Jul-12 13:47pm    
What happens when you debug the code?
a.fatemeh 6-Jul-12 16:42pm    
It has no error and it shows the form and when I press some keys nothing happen and the TextBox in the form is blank.
[no name] 6-Jul-12 16:51pm    
Apparently you do not understand. When you placed a break point inside this method that you are debugging, what happened when you stepped through the code? Did the break point hit all? What line was the break point on? Were lines skipped? Was this method called at all? We cannot see your project or your code. We can only rely on what you tell us the problem is.

1 solution

C#
YourWindowsFormClassName.KeyPreview = true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900