Some of my keyboard keys has gone, so I’m trying to program the other keys that are still working to press the damaged keys when I press them twice. Is that possible? Is there any program that can help me in doing that?
I want to remap the key J to give 'm' when I press it twice.
NB: My laptop is a MacBook Pro 13" Unibody Mid 2012
Set aliases for characters, strings or complete lines
UNLESS you are using wayland (Ubuntu 17.10, tested on Ubuntu Budgie 18.04, but Ubuntu Gnome 18.04 should be fine too), the snippet below will help you out.
How it works in practice
A box appears
Type your "alias" (e.g. jj for m), the result shows (m), and the text will immediately be inserted at cursor position (or, if you prefer, after tapping Ctrl).
This script provides a single solution to set aliasses for a character, a string or even complete lines, just set the "alias" in the lines:
In the latter case, typing "mb" will paste "monkey eats banana":
Setting up
You need to satisfy a few dependencies:
pyautogui:
pyperclip:
python3-xlib
Log out and back in.
Copy the script below into an empty file, save it as
replace_keys.py
Set up your aliasses (KEEP THE INDENTATION!) in the section:
If you want, change
into
if you like to insert immediately without tapping Ctrl
Set up a shortcut key with Ctrl as modifier. I used Ctrl + J in my test to run the script by the command:
And you're done!
I have two machines that have this problem of worn out/broken keys. I have found two solutions:
Spend ten bucks for a WiFi USB keyboard (Logitech has a good one). Generally the BIOS will see it and grab it before the OS.
Load a remote control piece of software (RealVNC is free for small setups and will cross different OSs)
Both work depending on the access needed.
Although @jacobvlijm 's answer is more specific, another alternative is to use a program like AutoKey . It does many things to automate your desktop by generating keyboard and mouse input from trigger phrases and hotkey presses.
In particular, you can define a phrase for each of the broken keys and have it triggered by a trigger phrase that is any combination of working keypresses not likely to occur in your actual typing. These phrases can be set to trigger immediately from within a word.
There's also an option that puts the trigger text you just typed back in if you immediately press the backspace key if you ever need the trigger characters as is.
All of this can be configured using the AutoKey GUI interface with no actual coding required.
For more complex requirements, AutoKey can run full Python scripts triggered by phrases or hotkeys which are only limited by the user's imagination and knowledge of Python.