Hello,
I had a very simple script for AutoHotKey under Windows which mapped the arrow keys to WASD and similar. I found out that there is an imitation for Linux called ahk_x11. So I installed ahk_x11 from the AUR and it seems to work with my script too (I had to adapt it a little, or rather delete the entry #IfWindowActive, as the function works differently in akh_x11). But now there is a problem. If you press two keys at the same time, e.g. W+D to navigate to the top right, one key remains stuck or pressed, as if it doesnât recognize when the key has been released. This makes it impossible to play in the heat of the moment. After some searching, I found many supposed solutions. I often read about xdotool, xinput, xbindkeys and xremap. But now Iâm desperate to implement it. I thought (after my research) xremap would be the easiest way to do it.
What should happen:
The script should load automatically (it doesnât have to, I can click on it every time before I start the game but it would be nice to have).
It should only be active when the game is running.
It should remap keys without any hangs or bugs!
In the game you can open the chat with enter and send the message with enter, so (in the Windows version with AutoHotKey) I suppressed the script when you pressed enter to open the chat and be able to write ânormallyâ and activated it again when you pressed enter again to send the message. That worked great and should also work with the new solution.
Can you please help me implement it like this.
Info:
KDE Plasma @ x11
EDIT: I forgot to mention I am on Nvidia
echo $XDG_SESSION_TYPE î˛ â
x11
wmctrl -x -l î˛ â
...
0x09a00003 0 steam_app_231430.steam_app_231430 tom-pc Company Of Heroes 2
sudo xremap ~/.xremap_remap.yml î˛ 1 â
Selecting devices from the following list:
------------------------------------------------------------------------------
...
/dev/input/event3 : Logitech K400 Plus
...
------------------------------------------------------------------------------
Selected keyboards automatically since --device options weren't specified:
------------------------------------------------------------------------------
Error: Failed to prepare input devices: No device was selected!
Maybe it would help to set a higher priority to the ahk_x11 process, I donât know.
And just to clarify. No, it is not possible to set the hotkeys in the menu of Company of Heroes 2. This is a huge flaw for a real-time strategy game but otherwise it is one of the best RTS games.
xmodmap might be ok for this (as youâre using X11) but itâs been deprecated for a long time, and itâs been ages since Iâve used it. I prefer custom layouts myself.
For this I might suggest a custom keyboard layout, as you can switch between layouts easily with a keyboard shortcut and itâll also work on Wayland (unlike xmodmap).
I can make one for you, if you tell me which layout youâre using and clarify a couple of things (as Iâve never used autohotkey or ahk_x11).
Just to be clear youâre saying you want w to act as the up arrow key?
As I wrote above
Press enter surpessed the script, so you can write normal in the chat (without the remapped letters) and press enter again activate the script
it should work somehow like this (I have no programming knowledge) :
var remap_is_active = true
If enter_is_pressed:
remap_is_active = ! remap_is_active
If remap_is_active & WindowIsActive ("name_of_the_application"):
w = arrow_up
d = arrow_down
.... etc.
else:
w = w
d = d
.... etc.
or maybe (I really donât know):
If enter_is_pressed:
remap_is_active = ! remap_is_active
If remap_is_active & WindowIsActive ("name_of_the_application"):
start xremap.my_script
else:
kill xremap #or whatever tool is used
I think this could be realized with a combination of xdotool and xremap but I just guess
Just tested this idea (using a custom keyboard layout) with a native game (urban-terror), and it worked there. I donât know if itâll work with a steam game, but Iâd say itâs worth a try.
Itâs not quite the same, thereâd be no check to see if the game is running. Just a key or key combo to switch keyboard layout manually and it wouldnât be Enter (well it could be Enter to turn if off, but turning it back on would require a different key or a combo otherwise you wouldnât have an Enter key anymore).
Would that be acceptable?
Iâd still need to know what keyboard layout you use (for instance I use English UK also known as gb).
Perhaps, but Iâve barely used xdotool and never used xremap. Not sure youâd need both, but Iâd have to research it to know for sure.
EDIT:
If you can use global keyboard shortcuts within the game then we may be able to check if the game is running.
System Settings â Keyboard â Keyboard â Key Bindings â Switching to another layout
See which key or combo youâd like to use, if you want something that isnât there I may be able to do that too.
In fact if you choose an option, and add another layout for testing you could see if this will work. If you can switch layouts in your game it should work.
It would help if I could read German, but yes that seems to be the one. Just any existing layout that you can distinguish inside the game, for instance when typing a message.
OK, I set german layout QWERTZ on ctrl*F11 and english layout QWERTY on ctrl+F12
And it works!
So that would be a possible workaround for now. But before you make too much effort, Iâll be honest. I would prefer a solution with a script as mentioned at the beginning.
But this idea is better than nothing at least for now