English Remapping Single Key to Mouse Button in Linux

3 replies
Goto Page
To the start Previous 1 Next To the start
Up
MikuAuahDark
User
Offline Off
TL;DR: Is there a way to somehow remap single key to mouse down and mouse up?

I want to use "Z" as my mouse click button (holding "Z" means holding mouse click) but I want it only if there are no key modifies, so Ctrl+Z is passed as-is, but "Z" alone acts as mouse click.

Background: I'm currently learning digital drawing. Since I don't have drawing tablet, I have no choice other than using mouse for movement. I'm using Krita for this and sadly adding keyboard shortcut to "Activate" it in Krita setting doesn't work (because it never meant for that). A solution would be using AutoHotkey which works in Windows like this:
Code:
1
2
3
4
5
6
7
8
#IfWinActive ahk_exe krita.exe
z::
     Click down
     Keywait z
     Click up
     return

#IfWinActive

However, I'm slowly moving my stuff from Windows to Arch Linux, so I can't use AutoHotkey. The equivalent, AutoKey sounds interesting but it lacks exactly feature that I want. I'm considering creating one myself using Xlib API (or XTEST) but I'm absolutely clueless on how to use the API to achieve what I want.

If anyone knows please let me know below or hit me up in UnrealSoftware Discord server at #off-topic channel, thanks.

EDIT: I've solved it. I had to write C++ code that interacts with X directly. See https://gist.github.com/MikuAuahDark/3e1a5b3946d8700e1a26769cc0f8e554
edited 1×, last 08.09.20 04:55:44 am
file cs2d LuaJIT for Dedicated Server (11) JIT POWER! | Know your Lua errors! | Draw stuff at Pixelize Art --xx-- server!
21.08.20 06:31:05 pm
Up
Cebra
User
Online On
maybe this software is something for you: http://www.nongnu.org/xbindkeys/xbindkeys.html
loading...
21.08.20 09:58:14 pm
Up
VADemon
User
Offline Off
Look towards defining a "custom keyboard layout". Maybe it's possible there (should be?..)
I did that, it's basically copying the existing config and refining the key mappings to fit your style. I did it to enhance en-US layout with German letters. It's a bit much to figure it out the first time (quite a few places (files) to touch), but not hard if you follow the guides.
22.08.20 04:52:36 am
Up
MikuAuahDark
User
Offline Off
@user Cebra: I looked at xbindkeys and it looks like there's no way to do something like this
Code:
1
2
3
4
5
1. Check if "Z" is pressed down
2. If it was previously pressed down (handling key repeat), stop
3. Press left mouse button (easy with `xdotool mousedown 1`)
4. Wait until "Z" is released
5. Release left mouse button (`xdotool mouseup 1`)

The steps above must be done sequentally, and I can't find if that's possible to use xbindkeys for that.

@user VADemon: Custom keyboard layout sounds too overkill for me. I don't want it applies to all users, but just myself, and only to specific application (Krita in this case).
file cs2d LuaJIT for Dedicated Server (11) JIT POWER! | Know your Lua errors! | Draw stuff at Pixelize Art --xx-- server!
To the start Previous 1 Next To the start