Skip to content

auto typing when pressing a specific key?

hello,

i tried asking this on other subs but have had no success.

ive been searching for a way to create a script that when i press a specified key it will type said comment, regardless of the window.

so for example if i press F5, i would like it to press enter, then type "hello world"

so far ive tried, autotyper by muru, linux mint's autokey, autohotkey, either via crossover or wine. none of these seem to work or are able to accomplish what im looking for.

in the event that it matters, im using no DE, (only AWM).

2 points7 comments
Open on Reddit
About this post
Posted
Archived
Score
2 · 100% up
Kind
Text
ID
86fr27

Author

12
posts
59
comments
1
media
View profile

7 comments

Try writing an sxhkd rule that runs xdotool.

Something like:

F5
    xdotool key Return
    xdotool type 'hello world'

↑ Write that to ~/sxhkd/sxhkdrc and run sxhkd, then press F5 to test.

If you want it to run when starting X11, put sxhkd & in ~/.xinitrc.

2 points

hmm, its not working, for some reason its like it attemps to write but no output is typed.

basically it attempts to say hellow world when the key is pressed except it just flashes the cursor and then nothing is typed. almost as if the "return" is affecting it? if i spam press it, sometimes more letters come through but its vastly inaccurate. no idea why.

EDIT: so i tried removing the return and just left the 2nd line of hello world and it only ends up typing "rld". very strange

edit 2: so reading issues online and messing around i found that unless i increase the delay to a ridicules amount and type extra letters like "hhello wworld" only then it will work properly. but its still kinda terrible tbh. return just straight up doesnt even work.

1 points

I did some tests and it seems like xdotool does funky things when multiple invocations of it are used to type things in rapid succession, especially if some keys are already pressed at that time.

Here's a fixed sxhkdrc:

@F5
    xdotool key Return type 'hello world'

This works for me. The @ marker makes the command be run on key-up, so the held-down F5 key doesn't interfere. Multiple commands given to a single invocation of xdotool also don't interfere.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.