-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include more sophisticated regex/exclusion features #161
Comments
First of all, this should work, so it's a valid issue. I have never seen an example of a successful exclusion pattern. This is something a number of users (including me) want. Problem: The version and version number of AutoKey you are reporting is impossible. The old AutoKey went as far as 0.91.x. The new one (which used to be called autokey-py3 - and is now just autokey) started out somewhere around 0.93 and is currently (or about to be) 0.95 - depending on how you install it. If your version is reporting 0.90.4, it is approximately four years old and very out of date. (We don't control what versions of AutoKey are packaged by any distributions.) Please backup all your macro and phrase definitions then completely uninstall AutoKey. Once the new version is up and running, you can restore your phrases and macros from your backup. Don't forget to backup and restore the hidden files as well. There's one for each macro and phrase. We currently only have PPAs for 16.04 and 18.04 and those probably won't work for you. The manual install works fine, but sometimes there are issues with getting all the dependencies installed properly. If you get stuck during installation, the place to go for help is on Gitter. You'll end up with a very much improved version of AutoKey, but it will probably still have your issue. Fixes (if any) for this issue will only be applied to this new version, so you'll need it anyway. |
AutoKey uses the regular expressions built into the Python standard library: https://docs.python.org/3/library/re.html |
@josephj11 @luziferius |
Is it possible that Autokey "swallows up" key triggers for phrases when the window filter excludes the current window? |
@dogweather Can you please create a new issue for this? That is something else. |
@luziferius Sure, will do. |
This is an issue I also had. I dug into the code and found these lines to be the cause: https://github.com/autokey/autokey/blob/master/lib/autokey/model.py#L331-L337. The logic here is that it tries to match the regular expression with either window title or class. This wouldn't work for exclusion because the regular expression must negate both title and class at the same time! Consider this example: we want to exclude window that has title |
@zefei 💯 Thank you for digging up the location. So @dogweather’s issue is indeed related. |
Uncoupling them would be an improvement anyway - you were already thinking about it. I just hope it's not too much work. |
Is there any gut feeling about one of those being used more than the other? I.e., is it possible that nobody uses window class, and we can simply stop testing it, or vice-versa? |
You need both. If you want to allow the script to run on any window owned by an application, you look at the class which is relatively invariant, but if you want a particular window from that application, you need to look at the title too - which varies arbitrarily and often does not include the application name. |
Any update on this issue? |
I've got the following for a phrase and it's still executing in gnome terminal.
This is in AutoKey The above should not match a string with anything following the regex portion but I tried Am I doing this wrong? This seems to match the |
@kjs3 I'm not that familiar with Python regexes, so I may be wrong. It appears that you are (correctly) attempting to match the entire window title/class by bracketing your pattern with Also, since AFAIK, AutoKey looks at both the window title and class, getting negative conditions to work is particularly tricky because what works for the title may not work for the class and the reverse - as discussed above. |
@josephj11, you're right about the regex. It was working but moving the Also, window title not being negated was the root issue. Thank you for pointing that out! The fact that I want this phrase not applied in a terminal window where the title changes based on dir/git repo/whatever I setup further complicates things. At least in Ubuntu 19.04, the default title starts with your username and hostname. So that's predictable for my new install. I'll have to figure something out on another Arch install that has pretty fancy titles. For the moment I have the following regex which is working:
Ultimately, I think a new option to restrict matching to only the window class would be really helpful.
☝️ Something like that would be great. |
I did struggle with this as well – including @kjs3's example in the Wiki would be neat. |
For me (Kubuntu 18.04, Autokey 0.95) the code of @kjs3 didn't work. I don't find any way to exclude a window (/program) from an autokey's phrase... |
Ubuntu 18.04, Autokey 0.95.4 - @kj3's code didn't work for me either. |
See issue #305 which will help with this if/when it is implemented. |
Hi all, Whilst having working regexp, including negation, would certainly be a step in the right direction, it's hardly user friendly, as the expressions are rather obtuse, even for those handy with regexps. In AutoHotKey, it's as simple as saying IF !(WinInClass('Terminal) or WinInClass('Emacs')) Is anyone further along in doing this? |
Thomas hasn't commented on this recently. He was gone for the summer and is back now. Since this seems to be a relatively important enhancement, it's likely that he will get to it (but I can't speak for him.) We don't know how hard it is to do yet. |
Any update on this issue? I'm loving using Autokey, but can't come up with a Regex to exclude Auotkey of working in VS Code which class name is |
Hi hakantakiri. I've been working pretty hard on a major revamp of autokey to support Emacs key overloading, and one of the things needed for that is solving this issue. I thought about what small revamp of regex I could do to fix this, and concluded the real way to solve it is the python way, to make the matching a mini script... if re.match("google-chrome", window.active_class): |
@hakantakiri I use python scripts to exclude VScode and Jetbrains IDEA:
|
@katoquro That sort of logic works, but the script still gets triggered on windows where it isn't appropriate and that stops other scripts/phrases from being triggered instead. That's why we need the root cause fixed. |
@katoquro Thanks for your workaround, but I noticed it caused some misbehavior for some scripts and phrases I have for other use cases. Finally I found a Regex that properly excludes VS Code without messing with the source code, but it requires certain conditions: "filter": {
"regex": "^((?!Code$).)*$",
"isRecursive": true
} Notice that The python script I run to kill and restart Autokey is the following: import os
os.system(''' pgrep autokey-gtk | xargs -I {} kill {} ; autokey-gtk ''') |
In theory, the isRecursive just allows you to not have to add the same regex to each key combo in the folder I'm not sure what you mean by new VS Code windows "doesn't exclude autokey". Maybe you mean autokey doesn't activate in a new window? Maybe you'd be better off running my version of the code, because it works fine for that scenario it seems. I've been fixing bugs along the way, and maybe there was one there I fixed. I think my version of the code is stable, but I haven't done a QT update, so as long as you're using GTK, you'd be fine. And I'm planning a menu item to install Emacs keybindings which I haven't done yet. |
@xpusostomos I'll give more context; what I want to achieve is to avoid some Autokey scripts or phrases to work when I'm inside VS Code, this is because they misbehave horrendously because of conflicts with native VS Code keybindings. I thought that maybe a Regex Putting VS Code aside, the thing is that, as shown in this issue and others, there are some users as myself that need a way to exclude AutoKey to work on a given program. The opposite of what |
@hakantakiri Yes. Attached is a screen shot of the filter window in my version of the code where I exclude Emacs, Intellij, the terminal and VS Code from my emacs keybindings. And yes, it seems to work fine for newly created Code windows. Because its python you've got complete control. |
#305 is where the code needs some attention. It will probably solve this issue as well. I'm glad see someone else working on our codebase. Could one or both of you come over to Gitter and explain this "isRecursive" thing to me. I've never seen anyone even mention it before although I wondered what it was. |
@xpusostomos Where we can find this fork? It looks OK for my cases (exclusion for some apps). For Idea and VS Code you can use more simple construction than regex like |
@katoquro This would be in @xpusostomos 's personal repo. We'd love to get this into our develop branch, but our previous lead developer left the project and, currently, I'm the only one with full access and I'm not a Python/AutoKey dev, so I'm only merging trivial/isolated changes. As soon as someone qualified takes over as lead developer, we'll start merging the more substantial changes like this one into develop and working toward getting new releases out the door again. |
@katoquro , my repository is here: https://github.com/xpusostomos/autokey As you point out, with this scheme you can use startswith, or regex or whatever you like. @josephj11 Do you want me to be the lead developer? |
@xpusostomos Thanks for the offer! Propose that on Gitter and see what feedback you get. It's not up to me. I just have the "keys". When you do, tell us a bit about your qualifications. How much do you know about building releases for us and working with other developers to review and merge PRs? How much time do you have for AutoKey? And anything else you want to share. There aren't any requirements to be lead developer per se, but I would want to know you plan to stick around for awhile and have the time and interest to do it. We currently have at least two other developers and I would hope they would be good with you taking the lead. I certainly can't do it. Totally aside: Can you give me a clue as to how to pronounce your name/handle? I'd also like to know what time zone you're in. It's not that important, but it gives us an idea of when you might be likely to respond to something when a discussion requires some back and forth. |
@xpusostomos, could you explain a bit more? What the branch contains that feature? I've tried to install this branch
but it doesn't start
|
Hi! I also have this problem. It seems that autokey priorities on specitivity with regexes. Is this correct? Or is it perhaps filenames? I made it to work this way, using "duplicated hotkeys": Then I created another file with regex .*Gnome-terminal$ and mapped ctrl+u to ctrl+u with send_keys. Bit of workaround, and and one extra file per command you want to keep, but it seems to work for me, and terminal is excluded for that command. Is this an OK approach or do you have any better idea? Although a bit similar to the Python logic above.. |
@katoquro Sorry the late reply, I only just saw this. I think you'd be best on master branch if you want to try it out |
@xpusostomos AFAIK, no one else has reviewed your code, so it was never pushed into develop. Since it's a major enhancement, I don't think it should go into the main branch until 0.96 is released. |
@josephj11 any idea when 0.96 will be released? |
We have no lead developer(s), so there is no one to create/test/release a new release. Until that changes, we're stuck. We are making commits to develop, so people could clone that, but I know some of the changes there are incomplete and certainly have not undergone any QA. Bluedrink9 just requested and received admin access to AutoKey, so he can do everything and is the closest person we have to a lead developer, but he doesn't want to take on that role/responsibility (and that's fine with me. He is a valuable contributor.) For now, I am the de facto project manager. I will do commits to develop when anyone requests them once they have been reviewed by a developer I trust who says they are safe or if they are isolated and trivial enough that I can determine that myself. As of now, I trust Bluedrink9 and, to a lesser degree, you and Sam. This is based solely on time and experience with the project. It has nothing to do with personalities, agendas, etc. I like everyone who is a part of this project. I am not a Python dev, so I can't even evaluate your Python programming expertise. What you and Sam have done looks very good to me, but I don't know enough to go beyond that. |
I'll address a 0.96 release in the Gitter. I'm keen to get one out, but I'd like to create a beta release first from a frozen develop commit (i.e. continue committing to develop, and meanwhile have a new branch based of develop that does not change, that people test as a beta branch.) |
At a rough guess, I'd say we're maybe 2 months away from a 0.96 release. That is somewhat dependent on how many beta testers we get though |
Best news I've heard in quite awhile! I'll have to get myself setup for using the beta. |
Very rough guess though haha, because it assumes almost no bugs found in the beta. Creating the release should take less developer energy than fixing bugs, so if bugs do crop up it may take a while to fix them. |
A workaround to support Mac-style copy/paste shortcuts that don't break the terminal is:
This solves the problem of Autokey "eating up" the keypress even when you have a rule being filtered out by giving it a new positive rule to follow. |
@starun96 this worked for me |
Classification:
Feature
Reproducibility:
Always
Version
AutoKey-Py3 version 0.90.4 / 3.6
Installed via:
sudo apt install autokey-gtk
Distro: Ubuntu GNOME 17.10
Summary
When creating shortcuts, you can provide a regular expression to make sure the shortcut only works on applications whose class names match. However, I have had much difficulty coming up with a regular expression that excludes applications based on their class name.
For example, I have shortcuts for copy and paste that send the
<ctrl>+c
and<ctrl>+v
keys, respectively, to any application I'm on. However, I don't want these shortcuts to be enabled for the terminal (URxvt), since it doesn't register those keybindings as copy and paste and it performs a completely irrelevant action upon using those shortcuts.It would be nice if I could simply provide a regular expression that excludes certain class names or, better yet, have the ability to simply click on a particular window to exclude it, just like how I can use the detect properties feature to include an application window.
Or maybe I can make it so that I can use one shortcut that sends different keys depending on the application I'm currently on. So
<alt>+d
would send<ctrl>+c
to my browser while<alt>+d
would send<ctrl>+<alt>+c
to my terminal.What I've Tried
I've tried using the regexes
(?!^Terminal$)(^.*$)
and^((?!Terminal).)*$
, to no avail. It doesn't seem like any exclusion filters work, from what I've searched on the internet. I don't even know which type of regex autokey uses.I eventually decided on creating a shortcut that bound
<alt>+d
to the following script:I did the same for paste (replacing the
c
withv
) and now copying and pasting works everywhere. However, I feel like for functionality as simple as this, it should be a standard feature and not something the user has to code in.The text was updated successfully, but these errors were encountered: