Giter VIP home page Giter VIP logo

skr's Introduction

Simple Key Remap

SKR is a low level, low latency way to remap keys. Some of the features of SKR are:

  • Remap keys
  • Remap keys to run a shell command or script
  • Remap keys to run a sequences of keys, commands, and scripts (A.K.A Macro) (needs documentation but it's there)
  • Function Layers
  • Multiple keyboard support

SKR sits very low in the keyboard stack just above the kernel. Thus, it is independent of display protocol, desktop environment, or window manager. It even works in tty.

Table of Contents

Installation

Arch Linux

Install skr from the aur with the package skr-git

example using yay AUR helper

yay -S skr-git

Ubuntu 20.04

First install interception-tools and git

sudo apt install git libudev-dev libevdev-dev libyaml-cpp-dev cmake build-essential
git clone https://gitlab.com/interception/linux/tools.git
cd tools
mkdir build
cd build
cmake ..
make
sudo make install
cd

Install skr

git clone https://github.com/DavRack/skr.git
cd skr
./install.sh

Fedora 32

First install interception-tools and git

sudo dnf install git cmake yaml-cpp-devel libevdev-devel systemd-devel gcc-c++ @development-tools
git clone https://gitlab.com/interception/linux/tools.git
cd tools
mkdir build
cd build
cmake ..
make
sudo make install
cd

Install skr

git clone https://github.com/DavRack/skr.git
cd skr
./install.sh

Uninstall skr

./install.sh -u

Configuration

SKR is configured through ~/.config/skr/skr.config. You can find an example config file here

Once skr is installed, run:

skr --init

This command will prompt you to press a key. skr will find the path of the keyboard used to press the key and will create a config file

Editing the config file

First we need to define the keyboard path for skr to intercept:

if you ran skr --init, the keyboard path will have already been defined

KeyboardPath -> /dev/input/event3

Key remap

A key remap makes a key behave like it is another. It uses the following syntax:

[keyToRemap] -> [targetKey]

Example: Remap CapsLock to Esc

CapsLock -> Esc

skr takes its key names from /usr/include/linux/input-event-codes.h

Here's a key code table with all valid key names: keycode table

Key swap

A key swap remaps two keys to each other. It uses the following syntax:

[Key1] <-> [Key2]

This is equivalent to the following remaps

[Key1] -> [Key2]

[Key2] -> [Key1]

Example: Swap Meta/Super ("Windows" key) with left alt:

META <-> ALT

Scripts

SKR can map a key to a script or shell command. It uses the following syntax:

[KeyToRemap] -> Script=[your command or full path to a script]

Example: log memory usage to a file located in /tmp/memlog

[KeyToRemap] -> Script=free -h > /tmp/memlog

Warning! all commands launched from skr will be executed as root

Layers

A layer is a set of additional key bindings that can be reached by holding down a key. It is easier to understand with an example:

Let's say you want to use H J K L as arrow keys (vim style). You can use capsLock as your fnKey When you hold it down and press H, J, K, or L they will act as arrow keys. When the fnKey is not held, H J K L will work normally.

The syntax for layers is:

NewLayer -> [fnKey]
    # all remaps after NewLayer will only activate when [fnKey] is held down

    # remap 1

    # remap 2
    .
    .
    .


# you can define multiple layers
NewLayer -> [fnKey2]
    # all remaps after NewLayer will activate when [fnKey2] is hold down

    # remap 1

    # remap 2
    .
    .
    .

The HJKL example would be written like this:

NewLayer -> CapsLock

    H -> LEFT
    J -> DOWN
    K -> UP
    L -> RIGHT
Some things to keep in mind about layers
  • When a Layer is defined, its function key stops working as a normal key

  • You can define anything inside a layer: remaps, scripts, and macros

Auto start (systemd)

To run skr on boot first we need to create a unit file at /etc/systemd/system/[email protected] with the following content:

[Unit]
Description=Low-Level key remapping

[Service]
User=root
Environment=USER=root
Environment=SUDO_USER=%i
ExecStart=/usr/bin/skr

[Install]
WantedBy=multi-user.target

Then enable the unit by running:

replace your username where indicated

sudo systemctl enable [email protected]

This will start the service at boot. To start skr immediately, run:

sudo systemctl enable --now [email protected]

Dependencies

TODO

  • MD custom macros
  • Don't run non sudo commands as root
  • Remove dependencies

skr's People

Contributors

aaronamk avatar davrack avatar mpldr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

skr's Issues

Crash on fedora32

It appears to be crashing on fedora:

(gdb) run                                                                                                                                     
Starting program: /usr/bin/skr                                                                                                                
[Detaching after vfork from child process 226841]                                                                                             
malloc(): corrupted top size                                                                                                                  
                                                                                                                                              
Program received signal SIGABRT, Aborted.                                                                                                     
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50                                                                         
50        return ret;                                                                                                                         
(gdb) bt                                                                                                                                      
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50                                                                     
#1  0x00007ffff7dfb895 in __GI_abort () at abort.c:79                                                                                         
#2  0x00007ffff7e568c7 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7f67e1d "%s\n")                                  
    at ../sysdeps/posix/libc_fatal.c:155                                                                                                      
#3  0x00007ffff7e5ddec in malloc_printerr (str=str@entry=0x7ffff7f6610c "malloc(): corrupted top size") at malloc.c:5347                      
#4  0x00007ffff7e614d7 in _int_malloc (av=av@entry=0x7ffff7f999e0 <main_arena>, bytes=bytes@entry=1024) at malloc.c:4107                      
#5  0x00007ffff7e62534 in __GI___libc_malloc (bytes=1024) at malloc.c:3058                                                                    
#6  0x00007ffff7e4bfc4 in __GI__IO_file_doallocate (fp=0x7ffff7f9a500 <_IO_2_1_stdout_>) at filedoalloc.c:101                                 
#7  0x00007ffff7e5ad20 in __GI__IO_doallocbuf (fp=0x7ffff7f9a500 <_IO_2_1_stdout_>) at libioP.h:948                                           
#8  __GI__IO_doallocbuf (fp=fp@entry=0x7ffff7f9a500 <_IO_2_1_stdout_>) at genops.c:342                                                        
#9  0x00007ffff7e59eb8 in _IO_new_file_overflow (f=0x7ffff7f9a500 <_IO_2_1_stdout_>, ch=-1) at fileops.c:745                                  
#10 0x00007ffff7e58f66 in _IO_new_file_xsputn (n=5, data=<optimized out>, f=<optimized out>) at libioP.h:948                                  
#11 _IO_new_file_xsputn (f=0x7ffff7f9a500 <_IO_2_1_stdout_>, data=<optimized out>, n=5) at fileops.c:1197                                     
#12 0x00007ffff7e41730 in __vfprintf_internal (s=0x7ffff7f9a500 <_IO_2_1_stdout_>, format=0x403015 "out: %s", ap=ap@entry=0x7fffffffd870,     
    mode_flags=mode_flags@entry=0) at ../libio/libioP.h:948                                                                                   
#13 0x00007ffff7e2e43f in __printf (format=<optimized out>) at printf.c:33                                                                    
#14 0x000000000040169f in cat ()                                                                                                              
#15 0x000000000040269e in main ()                                    

I haven't debugged further

skr not working on ROCCAT Vulcan AIMO

I have the above keyboard and am running it with eruption. I have tried pretty much every device listed in /proc/bus/input/devices but without success. If I can help debugging I'll be more than happy to help.

skr v2, new config file, rewrite in Go ideas and suggestions wanted!

Hi everyone!
Thanks to all of you for using skr, I know I've been very distant from the project (school and work can get in the way sometimes) but I have some ideas to improve skr, some of them I already decided but another ones I want some feedback. Some of the things I have already decided:

  1. skr will be rewritten entirely in Go
  2. skr will have some new features like many to one remaps, tap key etc

the things I'm not so sure about:

  1. config file: I think we need to use a standard config file like JSON, YML or HCL. I love JSON for data exchange, but I don't think it would be a good fit for skr, I think yml is fine but it being indentation only makes it a bit flaky, I think the best option would be hcl, but I want to hear what you guys think.

I hope with skr v2 we can solve all current open issues. As always, if you have some suggestions, I'm happy to hear them
(any other things I would be adding to this issue)

An aur package

This software is INCREDIBLE. It definitely deserves a place in the AUR, thank you for the hard work!

Automatic keyboard detection

I think which keyboards to use with skr can be entirely automated and can be done at runtime. This is important for users like me who hotplug their laptops into docking stations and such.

It should be possible to use /proc/bus/input/devices and then output like:

  85   │ I: Bus=0003 Vendor=046d Product=408a Version=0111
  86   │ N: Name="Logitech MX Keys"
  87   │ P: Phys=usb-0000:04:00.4-2/input2:1
  88   │ S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:04:00.4/usb5/5-2/5-2:1.2/0003:046D:C52B.0003/0003:046D:408A.0004/input/input29
  89   │ U: Uniq=408a-86-3b-a4-97
  90   │ H: Handlers=sysrq kbd leds mouse0 event5 
  91   │ B: PROP=0
  92   │ B: EV=12001f
  93   │ B: KEY=3f000301ff 0 0 483ffff17aff32d bfd4444600000000 ffff0001 130ff38b17c007 ffff7bfad941dfff ffbeffdfffefffff fffffffffffffffe
  94   │ B: REL=1943
  95   │ B: ABS=100000000
  96   │ B: MSC=10
  97   │ B: LED=1f

to detect keyboards attached to the machine. In this case for example keyboard will be available on /dev/input/event5 (See Handlers section)

Support multiple keyboards

I was looking at the parser code and the way it has been written, it appears that it can't support multiple keyboards.

For example - I am using skr to bind capslock to control, but as far as I can tell, I can define only one keyboard. This makes it hard to use skr on a laptop which can have external USB keyboards.

Could not find boost

Hi, when I go to install cmake using cmake .. I get this error:

`
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindBoost.cmake:2179 (find_package_handle_standard_args)
CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/andre/tools/build/CMakeFiles/CMakeOutput.log".

`

I stupidly thought I could ignore this however, when trying to run skr --init the config file I get does not look anything like the example one.

Apologies this is all new to me

Error on using KeyboardName in config

Following this new method to define keyboards, I got this error when using KeyboardName in the config.

Initializing skr
Traceback (most recent call last):
  File "/usr/bin/skr", line 126, in <module>
    keyboardPath = keyboardPathFromConfig(configFile)
  File "/usr/bin/skr", line 23, in keyboardPathFromConfig
    path = path.split("->")[1].strip()
IndexError: list index out of range

Here's my config file:

KeyboardName -> Keychron K6 Keyboard

Esc -> Grave
CapsLock -> Esc

Unclear error messages

20210217_08h44m57s_grim

So according to skr --init I have to run it using sudo (sudo -u name skr --init does not work obviously) and sudo skr --init tells me that it must not be run as root but works otherwise.

Dual Role keys [feature request]

A dual-role feature would be awesome. (see: here)
For example I have the CapsLock key mapped to a dual-role key on my programmable keyboard:

  • if you tap caps lock --> Esc
  • if you hold caps lock --> Ctrl

Other ppl also used

  • SpaceFN (spacekey: tap=space, hold=layerswitch)
  • space cadet shift (left and right shift keys: tap = parenthesis open/close, hold=shift)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.