Abdulrhman Alrifai
Abdulrhman Alrifai

Reputation: 45

Remap keys regardless of language

I want to remap the 'H' to 'V', but also when I am typing in Arabic I want to remap 'ا' to 'ر', the 'ا' and 'ر' are in the same keys as 'H' and 'V' respectively. so I tried to do h:: send v;. when I am typing in English everything is perfect but in Arabic, it actually types 'v' instead of 'ر'.

Note: I am currently checking the language and sending the keystroke in the appropriate language, but I am remapping a lot of keys so it is kind of tedious and I think there must be an easier way, Is there an easier way?

Thanks in advance.

Upvotes: 0

Views: 393

Answers (1)

Charlie Armstrong
Charlie Armstrong

Reputation: 2342

When you do Send v, AutoHotkey sends a v character. You don't want the character, though, you want it to push whatever key would be the v key on an English keyboard. You can do this using a virtual key code. The idea behind virtual key codes is that each code corresponds to a physical key on the keyboard, and not what character is produced on the screen. There are two ways to implement this.

  1. AutoHotkey has special syntax to find and use the virtual key code for a given character. You just enclose the character in curly braces, like so:
h::Send {v}
  1. AutoHotkey comes with tools that can be used to manually find the virtual key code for a certain key. This is useful if the key you need to press doesn't map to any character, or if AutoHotkey doesn't recognize the character it produces. The process below is quoted from the AutoHotkey documentation:
  1. Ensure that at least one script is running that is using the keyboard hook. You can tell if a script has the keyboard hook by opening its main window and selecting "View->Key history" from the menu bar.
  2. Double-click that script's tray icon to open its main window.
  3. Press one of the "mystery keys" on your keyboard.
  4. Select the menu item "View->Key history"
  5. Scroll down to the bottom of the page. Somewhere near the bottom are the key-down and key-up events for your key.

Make a note of the 2-digit value in the first column of the list. V is 56 on my Windows 10 machine, but numbers are platform-dependent. You can then use that 2-digit virtual key code in your send command, like so:

h::Send {vk56}

This syntax is documented here.

Upvotes: 2

Related Questions