How to emulate integrated numeric keypad cursor keys in linux - linux

On many older laptops and some compact keyboards there is an integrated numeric keypad in the main keyboard area. This alternate keypad is activated with a special 'Fn' key next to the left Ctrl key.
As a programmer I learned to use the cursor movement keys (arrows, PgUp, PgDn etc.) and found it greatly improved my programming speed. And the benefits were not bound to just a single application as is the case with specialised shortcut keys.
On conventional PC keyboards, the 'Windows Key' can be used to emulate the 'Fn' key and a corresponding integrated numeric keypad. When I used to use MS Windows I found Autohotkey was able to map the keys using a simple script.
Recently I learned about xkb and how it can be used to map keystrokes at a very low level.
What is the xkb keyboard mapping profile that will emulate an integrated numeric keypad using the windows key as the fn key?
Hint(?): I suspect the file will look a lot like the '/usr/share/X11/xkb/symbols/keypad' file on a Debian-derivative linux distro. This 'keypad' file is included at the top of the '/usr/share/X11/xkb/symbols/pc' file.
The corresponding autohotkey script for reference (# == WinKey):
#8::Up
#k::Down
#u::Left
#o::Right
#7::Home
#j::End
#9::PgUp
#l::PgDn
#m::Insert
#.::Delete
;(Scroll with the left-over keys)
#i::WheelUp
#,::WheelDown
Note that all these keys need to work with any combination of Ctrl, Alt, Shift as well as the Windows Key.

Steps to install numeric keypad-like cursor keys on the main keyboard in Linux / XKB...
xkbcomp $DISPLAY original.xkb (just in case ;)
xkbcomp $DISPLAY custom.xkb
Edit custom.xkb
Add the following at the end of section: xkb_types "..." {
type "WinKeyAsFnKey" {
modifiers = Shift+Super;
map[Shift] = level2;
map[Super] = level3;
map[Super+Shift] = level3;
level_name[Level1] = "Base";
level_name[Level2] = "Caps";
level_name[Level3] = "Fn";
};
Add the following at the end of section xkb_symbols "..." {
key <AE07> {type="WinKeyAsFnKey",symbols[Group1]=[7,ampersand,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<HOME>,clearmods=Super)]};
key <AE08> {type="WinKeyAsFnKey",symbols[Group1]=[8,asterisk,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<UP>,clearmods=Super)]};
key <AE09> {type="WinKeyAsFnKey",symbols[Group1]=[9,parenleft,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<PGUP>,clearmods=Super)]};
key <AD07> {type="WinKeyAsFnKey",symbols[Group1]=[u,U,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<LEFT>,clearmods=Super)]};
key <AD09> {type="WinKeyAsFnKey",symbols[Group1]=[o,O,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<RGHT>,clearmods=Super)]};
key <AC07> {type="WinKeyAsFnKey",symbols[Group1]=[j,J,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<END>,clearmods=Super)]};
key <AC08> {type="WinKeyAsFnKey",symbols[Group1]=[k,K,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<DOWN>,clearmods=Super)]};
key <AC09> {type="WinKeyAsFnKey",symbols[Group1]=[l,L,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<PGDN>,clearmods=Super)]};
key <AB07> {type="WinKeyAsFnKey",symbols[Group1]=[m,M,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<INS>,clearmods=Super)]};
key <AB09> {type="WinKeyAsFnKey",symbols[Group1]=[period,greater,NoSymbol],actions=[NoAction(),NoAction(),RedirectKey(key=<DELE>,clearmods=Super)]};
Save custom.xkb
xkbcomp custom.xkb $DISPLAY
I'm still working on the mouse scroll with 'i' and ','.
EDIT:
The above solution does not play nice with Google Chrome and Chrome-based apps (like Slack).
Alternative approach is to use a programmable keyboard. I use an after-market PCB for a CoolerMaster Masterkeys S keyboard. The Easy AVR layout is available online (although currently the left win-key now doesn't work by itself...I use the right one).

Related

How to turn off text overwrite mode in text editors?

I have used DevC++ and similar environments also have this application. While the overwrite mode is on the code overwrites instead of code moving to right.
The issue can be solved by using fn + insert(print screen) in Windows 8 or above and insert key in lower versions.
Like #Kokul says, you can press the Insert Key. If your Windows machine does not have a physical Insert key, you can press the virtual one, which you can find by pressing:
Windows Key > Ease of Access Keyboard Settings > Use the On-Screen Keyboard
Then press the Insert key which is located on the virtual keyboard to the right of the Enter key. Pressing the virtual key will behave like pressing the physical Insert Key.

Catching special characters with ncurses

I am currently working on a project for mapping every possible keyboard and mouse interrupt.
The mapping is done in linux environment and with ncurses library.
The question is how to catch the following keyboard keys :
Home
End
page up / down
when pressing those keys the terminal itself is catching them and the program itself cant see them (spent a few hours of configuration and found no solution yet)
pause/break (above page up in standard keyboard)
PrtScreen
Num Locked keys (0 to 9 and < . >).
Windows button
the following just not getting any response at all, neither from the terminal or the program.
short: you cannot catch all keys with ncurses
long: the usual problems lie in a failure to initialize things properly:
you probably forgot to call keypad(stdscr,TRUE) (or whatever window you might be using with wgetch). That will allow an application to read any of the keys defined in the terminal description as an integer.
If it is not in the terminal description, (n)curses will return the sequence of bytes which make up the key as sent from the keyboard.
That's two likely problems. There are other keys (or combinations of keys) which the terminal will not send (in a way which makes distinct keyboard sequences). For instance, using the Control key with other keys may change the sequence sent by the keyboard, or it may not. To see this, use experiment with the control key with comma, period or the other punctuation keys in that area of the keyboard.

Ins key on a mac keyboard in Linux

I am on a Linux (fluxbox/Mint) with urxvt using an external Mac keyboard. I can't find an ins key. In urxvt you can select a part of text, it automatically copies, and with other types of keyboards I could use Shift+Insert and it pastes the text. How can I paste the text with a mac keyboard running in a Linux? Needless to say, that I tried the standard variations of Ctrl+C and Ctrl+V, Ctrl+0, Shift+0, in combination with fn key.
Try Fn+Shift+return.
This works as middle-click paste under both Gnome (Wayland) and i3wm (Xorg) in Fedora 28 with my 2016 MacBook Pro 13,1 built-in keyboard (using an out-of-tree SPI driver). Hopefully it's the same situation for external Mac keyboards under other specific environments.
Maybe you can try fn + return to simulate the Insert key.
Another way, install AutoKey :
apt-get install autokey-gtk
and set a phrase to:
Phrase Text: <ctrl>+C (actually type out the <ctrl>+ here)
Paste Using: Keyboard
Abbreviation: None
Hotkey: <super>+v
Window Filter: None
If you want to use your Apple keyboard like a regular US-layout keyboard, with Alt on the left side of Meta, you can use the AUR package un-apple-keyboard. Currently it only works for the aluminium USB model.
The package does the following things:
Adds a /etc/modprobe.d/hid_apple.conf file which enables the F num keys by default, as in #Function keys do not work.
Uses keyfuzz to remap F13-15 to PrintScreen/SysRq, Scroll Lock, and Pause, respectively.
Swaps the ordering of the Alt and Meta (Command) keys to match all other keyboards, again using /etc/modprobe.d/hid_apple.conf, as in #Swap the Alt key and Command key (Meta/Super).
Applies these changes automatically when you plug in your keyboard, with a udev rule.
See more information from Archlinux wiki Apple Keyboard.
Try Fn+Opt+Return. Works for me.

Dvorak typers, how do you handle shortcuts like Ctrl-C?

Do you change the key binding in the OS to be, i.e., Ctrl-Q?
Do you manage to stretch your left hand to the C key?
Do you use right ctrl and press shortcuts with your right hand?
When I switched to Dvorak, I was using primarily Ctrl+Ins and Shift+Ins for copy/paste. Now I use Ctrl+C and Ctrl+V and other program-specific shortcuts, but I have just learned to use them in their "weird" locations.
A similar question was asked on SuperUser, with the following answers:
Use an AutoHotKey script to remap the keys. (Link)
Use Microsoft Keyboard Creator to remap them. (Link)
Install a third-party app that will remap them automatically. (Link, Link)
macs have it built in. there is a keyboard layout for dvorak with querty shortcuts. for windows, i use https://code.google.com/p/dvorak-qwerty/ it works well with ctrl and alt but dosen't work with the Win Key, which is not that bad.
The program AutoHotKey is what I use to map C,X, and V to their Querty origin.
I use none of the proposed solutions: instead, I modify CapsLock so that it becomes a dead-key that I use to program various actions. For example, when I press CapsLock and the key marked (in QWERTY)
S, this is mapped to Ctrl-X (and thus cut)
D, this is mapped to Ctrl-C (and thus copy)
F, this is mapped to Ctrl-V (and thus paste)
I, this is mapped to up-arrow
K, this is mapped to down-arrow
J, this is mapped to left-arrow
L, this is mapped to right-arrow
etc.
This is was dubbed 'Home Row computing' by Gustavo Duarte when he introduced this idea in https://manybutfinite.com/post/home-row-computing/ and then https://manybutfinite.com/post/home-row-computing-on-mac/
I'm pretty sure that this amounts for a large part of the speed I gained when typing, in addition to touch-typing.
On Linux, the solution that works great with some versions of Gnome on Wayland is this. It will set up all the rules on installation and will work transparently.
Previous answer:
Using Cinnamon, the following works when typing in some applications (i.e. vscode editor):
In keyboard settings, add QWERTY keyboard layout as the first in the list,
add Dvorak layout as the second
When typing text in an editor using the Dvorak layout, pressing Ctrl will still use the first (qwerty) layout.
This does not work in other applications, like Firefox browser, for example so can be pretty confusing.
Having a shortcut (i.e. Alt+Shift) for switching layouts assists in those cases.
While can be difficult at times, the advantage of this approach seems to be that it does not require additional software.
I've written Dvertkey, an AutoHotKey script, for this.
I've been a dvorak user for sixteen years, and for years I've used the various alternative keymaps mentioned in this thread, but all of them fall down when using a number of recent incarnations of Microsoft applications, such as the Office apps and SQL Server Management Studio. They seem to ignore Windows' own keymaps when using meta keys, rendering the hybrid layouts useless. AutoHotKey gets around this to ensure I get exactly what I want in any application.
I've been using Dvorak for so long now that I couldn't imagine remapping ctrl-c and other hotkeys to be in any other location than where they are supposed to be on the Dvorak keyboard. As for hotkeys, it's much easier and more natural to just use two hands to do the combinations. Use the left hand for ctrl and the other hand for the c-key. It would be too confusing to try and think ctrl-c and then press something else.
For the occasional windows game that requires WASD, I just switch the keyboard for the duration and if that means typing QWERTY sentences in chat then I just mentally switch and type a little bit slower.
Those characters are accessible with the right control key (a bit of a stretch for the x). If you are right handed, and have your right hand on the mouse, just move your left hand to the right control key and do the key combination

AutoHotkey diacrictics mappings not working correctly with Vim

I've been using some mappings in Vim to avoid having to switch keyboard layouts to type in diacritics in my language (Croatian). However, now I wanted to move these mappings "up" so that they're available globally. I tried using AutoHotkey for this. Here are the mappings I wrote
#CommentFlag //
!;::Send {U+010D} // č
!'::Send {U+0107} // ć
!]::Send {U+0111} // đ
![::Send {U+0161} // š
!\::Send {U+017E} // ž
These work great in every application I've tried (browsers, notepad, MS Word), but don't work in Vim, which is pretty annoying as I do most of my typing there. More specifically, only 'š' and 'ž' work as expected, while both Alt-; and Alt-' give me a 'c' (instead of 'č' and 'ć'), and Alt-] gives a 'd' (instead of a 'đ').
I'm using AutoHotkey_L (though I had the same results with the "regular" AHK), Vim 7.3 (trying this in gVim; it doesn't work in the terminal version either (in a slightly different way) but I don't really care about that) on Win8.
I can give more info on the Vim version, but it's basically one of those windows binaries from vim.org. Things I guess might be important is that it has +multi_byte, and I've been using Unicode in it with no problems whatsoever.
Update:
As per Ingo's suggestion below, I've tried using IfWinNotActive to not have the mappings present in Vim and continue to use my old ones there. Here's one example I've tried
SetTitleMatchMode 2
IfWinNotActive GVIM
{
#CommentFlag //
!;::Send {U+010D} // č
!'::Send {U+0107} // ć
!]::Send {U+0111} // đ
![::Send {U+0161} // š
!\::Send {U+017E} // ž
}
I've also tried many other variations with the Vim window class (using ahk_class), with #IfWindowNotActive etc., but to no avail... The mappings are still there in Vim. Btw, the window title always contains the string "GVIM", and AHK sees that as I've confirmed with WinGetTitle.
I don't have a solution, but a workaround: When I faced with the same issue, I decided to emulate Vim's digraphs globally (also using AutoHotkey), and just except Vim (and applications like Remote Desktop) from that feature (so that the full range can still be used there; my script only supports a subset). You can find my implementation here.
You can also edit a keyboard layout itself, using Microsoft Keyboard Layout Creator.
For example, the English one that you use: choose combination of some character and some function key (Ctrl or Right-Alt, with or without Shift − e.g. for Caps).
Here’s how it looks:
I find the Apple International US layout very good for this purpose, having all the accents available using dead keys, so I've implemented it with Microsoft Keyboard Layout creator like stansult suggested.
Then I came up with the problem of having only one "Alt" key usable, so I ended up remapping my Windows and Alt keys using ScanCodemap. This is a viable solution if you don't use the Windows key that often. One caveat of this method is, that you'll have to use Win+Tab instead of Alt+Tab from now on to switch between windows, it takes a couple of days to get used to that.
Windows Registry Editor Version 5.00
; 0x003a001d: Caps Lock (0x3a) -> Left Ctrl (0x1d)
; 0x0038e038: Left Alt (0xe05c) -> Right Alt (0x38)
; 0xe05b0038: Left Windows (0xe05b) -> Left Alt (0x38)
; 0xe05c0038: Right Windows (0xe05c) -> Left Alt (0x38)
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,05,00,00,00,1d,00,3a,00,38,e0,38,00,38,00,5b,e0,38,00,5c,e0,00,00,00,00

Resources