I am writing a key logger in windows 7 ( using SetWindowsHookEx ) and I need to know the correct keyboardLayout for the key being pressed. I tried getting the keyboardLayout from the ForegroundWindow and this works fine in most cases but in Internet Explorer 9 it doesn't work as expected (it returns the wrong layout ). I thought about getting the layout from the language bar ( because it shows the language of the window that is currently being typed on ) but I don't know how to retrieve this data. Maybe there is a registry key with this data or I can ask the language bar window for its text. Any ideas ?
Asked
Active
Viewed 956 times
1
-
You are writing a what?! What exactly is the purpose of your keylogger? – alex May 26 '11 at 08:41
1 Answers
2
Doesn't GetKeyboardLayout of WinApi do what you want?

MajesticRa
- 13,770
- 12
- 63
- 77
-
I does but it requires a thread id and I tried getting that thread using GetWindowThreadProcessId but it the Internet Explorer 9 case it gives the wrong result – jacob May 26 '11 at 08:45
-
-
Argh... Known issue. Here is an article http://blogs.msdn.com/b/oldnewthing/archive/2008/10/06/8969399.aspx – MajesticRa May 26 '11 at 09:16
-
You may have to combine http://msdn.microsoft.com/en-us/library/ms646292(v=vs.85).aspx GetActiveWindow(). – MajesticRa May 26 '11 at 09:17
-
But you can get thread from which the keyboard focus by using GetGUIThreadInfo with first parameter as NULL – MajesticRa May 26 '11 at 09:18
-