Jump to content
Tuts 4 You

Help needed / changing keyboard layout in a game

Starship Orion

Recommended Posts

Starship Orion
Hi! I'm new to reverse engineering and I'd like to get some help with my project with the game Heroes of Might and Magic 3. 


I'm trying to change the keyboard layout in the game to finnish language. I've opened the exe file of the game in OllyDBG 2.01 and Resource Hacker, but so far I haven't been able to find much anything helpful. 


I started the project by looking for any function calls that would be related to keyboard layout. However there are no cases of user32.LoadKeyboardLayout or user32.activatekeyboardlayout which I think would be the right functions to call. Yet the game always uses the US keyboard layout, even the Polish version of the game. 


There is some code where locale is mentioned, but when I put a breakpoint there the code is never executed. 


I also placed a bit of code in the exe file that calls user32.getkeyboardlayout and the result is 0x040b040b was placed in EAX, which means finnish keyboard layout. 




I think this code is more or less related to handling the messages. Am I right? At least user32.translatemessage is the function that is supposed to translate virtual key codes to ascii characters. 



Any ideas would be welcome!


Thanks in advance

Link to comment
Starship Orion
Thanks for the help but no, autohotkey won't change the keystrokes inside the game.


I'm starting to think that the virtual key codes are passed on unchanged to be interpreted as ascii codes. That's because virtual key codes from A to Z have exactly the same number in hex as ascii codes.

Link to comment
  • 1 month later...

I don't know if I am right but you can try global keyboard hook and change the keystrokes as needed.

There are plenty of source available.

Link to comment

The game may be hard coded to use a specific keyboard layout so you may not be able to accomplish this just by looking for a simple API call to alter. 


See if you find any calls to: GetKeyboardLayout


If the game uses DirectInput to map the keys, it will most likely make use of that and MapVirtualKey / MapVirtualKeyEx in order to translate the key (unless they use the raw DirectInput definitions for the keys.)

Edited by atom0s
Link to comment

I am not telling to Change the game program at all. I am telling to code a application which hooks to keyboard and handles the user inputs and then pass it as desired to the game.

Modifying the compiled game exe might be difficult but coding a app to do the keys modifications might be easy.

Ps: the app coded must be run at the time of playing game only :lol I think you know that.

Link to comment

Quickly searched and looks like HMAM is written w/ Qt? If so you'll need to patch inside keyPressEvent/keyReleaseEvent function in relevant widget. compile examples for more info - http://programmingexamples.wikidot.com/qt-events


If it isn't in Qt, then I'd start by id'ing the SDK the game engine is in, theres only so many (dont think its winapi though), then see how that SDK specifically handles keystrokes and go from there.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...