houmain / keymapper

A cross-platform context-aware key remapper.
GNU General Public License v3.0
257 stars 21 forks source link

[Feature Request]Text Cursor Context #127

Open rp1231 opened 2 months ago

rp1231 commented 2 months ago

I have set CapsLock{Right Half of my keyboard} as number pad keys. But I would only like to have this mapping enabled when the text cursor is active as it is pretty much useless otherwise. I would like the CapsLock to behave as the Control key when the normal mouse pointer is active. It would be great if there was a feature which enabled you to set mappings for when the text cursor is active. Thanks

ristomatti commented 2 months ago

IMHO this kind of feature should not be something for Keymapper to handle as a low level input device mapper. I'm not an expert on how this stuff works, but I would assume this would depend on the OS and possibly even application. Based on a quick search, it appears Windows has a mechanism to detect this but couldn't find a definite "yes" for Linux.

However, if you know a way to detect this in your specific use case, this should be possible with the recently introduced keymapperctl utility. You could then add virtual key e.g.:

TextInputMode = Virtual0

Then based on some external script, call keymapperctl --press TextInputMode when inputting text and keymapperctl --release TextInputMode afterwards.

Please share if you figure out how to do this on Linux. I too would find this useful for some purposes and something I was thinking about when I submitted #103 (ended up being implemented on #105).

ristomatti commented 2 months ago

Some discussions I ran across when searching:

rp1231 commented 2 months ago

Hi, Thanks for the detailed explanation. Unfortunately, I'm more of a poweruser rather than a programmer so it would be beyond my skillset to be able to implement this myself. Though I am aware of a google chrome extension that has the ability to do this and run systemwide by the use of native messaging. Maybe that can help you for your purposes. It doesn't support linux though.....

rp1231 commented 2 months ago

It'll be great if it can be implemented just for windows, if linux is not possible.

houmain commented 2 months ago

@rp1231 which browser extension are you referring to. Does it or any other application have this feature and does it work satisfactorily?

@ristomatti Thank you very much for your research! I also think that under Linux it is quite hopeless to make it work out of the box.

rp1231 commented 2 months ago

@houmain the extension I was referring to is https://www.autocontrol.app/. For eg. in this extension if you want to define the combination of Caps Lock + j to output 4 only when the text cursor is active, It would look something like this:

Screenshot 2024-04-23 083944
houmain commented 2 months ago

As far as I understand it, it does not work on Windows in general but only within the web browser, right? I think one would have to create a browser extension, which informs keymapper about the the cursor state using native messaging and keymapperctl as ristomatti said.

rp1231 commented 2 months ago

@houmain It does work on windows as well. The settings I showed in the screenshot enable you to do that. To use the extension, you need to install an extra exe as well which allows it to run system wide via native messaging.

ristomatti commented 2 months ago

I believe Grammarly can also do this on Win/Mac/Android/iOS as well but not on Linux. But it's a commercial product with likely a big team working on it full time...