Hello list,
I am new here, so I'll introduce myself a bit. My name is Rastislav
Kish, I am from Slovakia and just recently, I have switched my main
operating system from Windows to Ubuntu mate 20.04 64-bit. I've used
AutoHotkey on Win previously, and i considered using AutoKey as its
Linux alternative.
But I'm facing one big issue, which is capturing keyboard input
without letting it pass.
To explain what I mean, with AutoHotkey, I used to do the following:
Press ctrl+K shortcut, autohotkey script activated.
Write a short code of action which i wanted to perform, like sbf,
standing for Software, Browsers, Firefox, what was an action launching
Firefox. The script was tracking what I was typing, so immediately after
I hit f, it recognized, that there are no other possible sequences
behind sbf and launched Firefox.
import subprocess
subprocess.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
At ”Abbreviations”, click Set.
In the dialogue, create the shortcut ”.sbf”.
Make sure the rest looks as the following:
☒ Remove the typed abbreviation
☐ Omit trigger character
☐ Ignore case of typed abbreviation (actually this one could also be checked, it's up to you)
☐ Trigger when typed as part of a word
☒ Trigger immediately (don't require a trigger character)
Now hit OK and then save your script.
Now, where ever window is active, it shouldn't matter, type:
.sbf
Firefox should now launch right after you hit the ”f”. No need for ↵, ↹ or anything else. At least this worked for me.
Another way to look at it is that most GNU/Linux-distributions already are able to launch software with keyboard shortcuts, that is without the need of AutoKey. I don't currently use Mate so I can't tell you exactly how, but at least in Xfce it's fairly easy. I think it's equally easy in Mate. Personally I usually only setup the most commonly used software, for instance Super+f for File manager, Super+t for Terminal and so on. There are also software dedicated for this. It was a very long time I used such software, so I don't know which ones are available these days, but usually you hit some key to launch the launcher, like Super, and then you just start typing the name of your software. Of course it involves a small dialogue to open, so maybe it's not for you, I don't know.
Another possibility is probably to just write a script in Bash that launches your software.
read -n1 Key
The key you hit is stored in the variable Key and you don't need to press ↵.
I guess that could be used for a script that does the work.
When finished, associate that new script with Ctrl+k and then you should be able to use it the way you described, I think. I haven't tested this last one though.
Kind regards
Johnny Rosenberg
I have problems doing this in AutoKey. I have searched this group for
possible leads, finding an interesting mention of pyxhook library, which
is able to catch letters globally, however is unable to prevent them
from passing to focused window, so I can't use it.
Does anyone know of anything capable of this?
Ideal would be, if it didn't display another windows, as I want focus to
stay where it is, some of my scripts was using this for example for
Markdown to HTML conversion, where the source was the currently focused
edit field or opening a file in notepad instead of default program,
which used the currently focused entry in Windows Explorer.
Thank you in advance!
Best regards
Rastislav
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/df14f362-a317-104a-d44f-6bf73b778409%40gmail.com.
import webbrowser
webbrowser.get("firefox %s").open("about:home")
Hello,
exactly. I need to type the letters without the program being aware of that.
The reason is, that programs are quite sensitive to key presses. Various letters can not just toggle on or off functions of a program, but also directly interfere with the task I want to launch.
For example, combination fon, standing for functions, open with, notepad, was launching my script, which detected the currently focused file in Windows Explorer and opened it in notepad. Similarly fow would do the same just with Word, fog was opening the file in Goldwave etc.
However, if the input after pressing ctrl+K was not blocked, this wouldn't be possible, as pressing letters in any filesystem explorer would firstly select a completely different file.
Autohotkey had a very useful input function for this, which after launching blocked the keyboard completely and was reading input from it, until either an entry in matchlist was reached, or it was also possible to set a callback, where one could manually determine after receiving a letter whether to stop or not.
I personally don't have problems with code gymnastics, if I just
knew what to do. :)
I don't know how exactly broadcasting events in Linux works, so
may be it's about the time to find out.
Anyway, thank you all for your answers, the primary goal was to find out whether this doesn't exist already, so I wouldn't need to reinvent the wheel. I believe too that there must be at least some cheat to do this, but this is probably a question for more technically targeted place, such as Stack overflow.
Best regards
Rastislav
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/d92666d9-5c6f-4f7b-b7d5-b19ead487381o%40googlegroups.com.
#############################################################
# ABOUT THIS SCRIPT:
# If you set the Hotkey for this script as Ctrl+K,
# you can press that key combination to activate a GUI dialog
# that asks for input.
# You can then type specific key combinations and press the
# Enter key to launch specific browsers.
# In this example, any of these things can happen:
# * pressing Esc or clicking the Cancel button triggers a notification
# * pressing the Enter key or clicking the OK button triggers a notification
# * typing sbc opens Chrome
# * typing sbcb opens Chromium Browser
# * typing sbf opens Firefox
# * typing sbv opens Vivaldi
# * if something else happens, an error message is triggered
#############################################################
#Ask for input, offer a default example, and check the exit code of the command:
retCode, userInput = dialog.input_dialog(title="Input required",
message="Enter a browser shortcut:", default="example")
#If the exit code was 0, take the specified action:
if retCode == 0:
#If sbc was typed, open Chrome:
if userInput == "sbc":
subprocess.Popen(["chrome.exe"])#Windows only
#If sbcb was typed, open Chromium:
elif userInput == "sbcb":
subprocess.Popen(["chromium-browser"])
#If sbf was typed, open Firefox:
elif userInput == "sbf":
subprocess.Popen(["firefox"])
#If sbv was typed, open Vivaldi:
elif userInput == "sbv":
subprocess.Popen(["vivaldi"])
#If any other input was received:
else:
invalid = "You typed: " + userInput + "\n"
prompt = "Please enter a valid shortcut."
dialog.info_dialog(title="Invalid", message=invalid + prompt, width="250")
#If the exit code was 1, notify the user that the dialog was cancelled:
elif retCode == 1:
cancelled = "You pressed the Esc key or the Cancel button."
dialog.info_dialog(title="Cancelled", message=cancelled, width="200")
#If the exit code was anything other than 0 or 1, warn the user of an error:
else:
error = "Something went wrong."
dialog.info_dialog(title="Error", message=error, width="200")
Hey there,
Just for the heck of it, I thought I'd mess around a bit and come up with a proof of concept that doesn't quite do everything you want, but it does some of it and should head you in the right direction. It solves one issue in that if you set Ctrl + K as the Hotkey for it, it will listen for your keystrokes and intercept the moment that incantation is typed and then react to whatever you type next without sending your keystrokes back to the currently-focused window. What I don't know how to do yet is to get Python to figure out which file you currently have open and then open it in Notepad. Maybe someone else can jump in and help with that, but I'll probably still mess around with it if you don't mind my probably awkward and inelegant code.Without further ado, here's what I've got so far and it's working smoothly at my end (except for the Chrome.exe part, since I'm running the script in GNU/Linux and not Windows:
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/05d1d3b8-2ba5-4ae8-a69b-c7765db39653o%40googlegroups.com.