Script is Consistently Dropping Random Characters

19 views
Skip to first unread message

Wdav Ro

unread,
Apr 22, 2022, 7:24:54 PM4/22/22
to autokey-users
I'm using v0.95.10 on Ubuntu 20.04.4 LTS.
I've written 12 Autokey scripts to fill in different forms in a SalesForce webpage which is running in Firefox 99.0. When I run the scripts about 60% of the time it randomly drops a character. For instance, in the snippet below, instead of entering "email" it will enter "mail" or "eail" "emal" or sometimes it will drop a tab (which moves the cursor to another field) and that really messes up the form entry.
I've put the 'sleep' commands in to try to slow it down thinking Firefox is not keeping up, but it hasn't made any difference. Anyway the speed commands don't affect the speed of the send_keys command itself that might be doing the dropping.

These are my first Autokey scripts. Am I doing this wrong? Or is there a way to slow down the send_keys command playback? Or any other feedback?

A snippet of my code follows:

# BEGIN DATA ENTRY
keyboard.send_keys("<tab>")
time.sleep(0.15)
keyboard.send_keys("<tab>")
time.sleep(0.15)
# ENTER TEXT FIELD: SUBJECT
output = "Email"
keyboard.send_keys(output)
(... continues with another 10 or so tabs, and 5-6 send_keys)

Kreezxil

unread,
Apr 24, 2022, 11:11:31 AM4/24/22
to autokey-users
It's probably the send_keys method causing the issue.

Hmm, try sleeping for 0.2, as in the wiki for the clipboard operations, we're told that AutoKey needs that much time for the clipboard operation to be handled. I know you're not using the clipboard operation, but try that.

Something I've done in the past when this happens, granted it won't be helpful on single sends like <tab>, it does help on larger things like an email address.

#  A FUNCTION FOR YOU
def send_paste(data):
    clipboard.fill_clipboard(data)
    time.sleep(0.2)
    keyboard.send_keys("<ctrl>+v") # pastes the content of the clipboard

# to use it
output = "Em...@not.my.box"
send_paste(output)

Also, maybe try press_key for the <tab> sends

# PRESS KEY
keyboard.press_key("<tab>")

For faster help consider joining our Gitter. https://gitter.im/autokey/autokey

Wdav Ro

unread,
Apr 25, 2022, 6:19:32 PM4/25/22
to autokey-users
Thanks for the reply.

I'll try increasing my sleeps to 0.2 (from 0.15). I'll also put a sleep between the "output=..." and the send_keys and see if that helps.
If not, I'll look into your function. It''ll require more learning on my part.

Wdav Ro

unread,
Apr 26, 2022, 3:28:55 PM4/26/22
to autokey-users
Update: Well, so far, I've used the updated scripts (per my prev message) about 15 - 20 times and no dropped Tabs.

However, twice today the snippet:

output = "Remote Meeting"
time.sleep(0.2)
keyboard.send_keys(output)

showed up as "Remote Meting" on one and another time as "Remote Meeing".

I'll have to learn about, and implement, your function and see if that will improve things.

Thanks,

jos...@main.nc.us

unread,
Apr 27, 2022, 12:24:07 PM4/27/22
to autoke...@googlegroups.com
Hi. This is a generic problem with slow applications that can't keep up
when AutoKey types at machine speed.

The main offenders are LibreOffice and the Firefox address bar, but I
believe I've heard about Salesforce before as well.

For best practices, see
https://github.com/autokey/autokey/wiki/Emitting-Keyboard-Events .

I wrote it because we run into it so often and what works best is not
immediately obvious.

Because of this and other issues, the new default for phrases is Paste
using Ctrl+V in 0.96.0 (which is almost ready for release).

Joe
> --
> 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/bf47d382-a314-4614-9c13-75974315fd0an%40googlegroups.com.
>


Johnny Rosenberg

unread,
Apr 28, 2022, 1:49:49 PM4/28/22
to autoke...@googlegroups.com
Den ons 27 apr. 2022 kl 18:24 skrev <jos...@main.nc.us>:
Hi. This is a generic problem with slow applications that can't keep up
when AutoKey types at machine speed.

The main offenders are LibreOffice and the Firefox address bar, but I
believe I've heard about Salesforce before as well.

Strange. I use it all the time in LibreOffice Calc and I'd say the problems there are very rare. Also, Autokey isn't needed very much in LibreOffice, because LibreOffice has its own customizable autocorrect feature (Tools → Autocorrect → Replace). You can even have different phrases in different languages and an overall one.

In Firefox I almost never have any problem either. I'm writing this in Firefox right now and I almost insert my signature with AutoKey, and it never failed so far, as far as I remember. I use Autokey in the address bar too, and it usually works perfectly. Maybe it's a combination with software and hardware. Maybe I would have those problems on a slower computer, I don't know.

Anyway, to be sure to never run into those rare occasions, I wrote a simple function for that. I guess others have done similar things and mine is probably not better than anyone else's, but here it is:

def SendKeysSlowly(Text, Delay):
    for Character in Text:
        keyboard.send_keys(Character)
        time.sleep(Delay)

Example how to use it:
SendKeysSlowly("This text is typed slowly", 0.05)
In this case, 0.05 means that there is a delay of 50 ms (0.05 seconds) between each character.
Seems to work great and it looks cool too, if you pick the right delay… 😁


Kind regards

Johnny Rosenberg

Wdav Ro

unread,
Apr 30, 2022, 8:58:03 PM4/30/22
to autokey-users
I've switched all my sendkeys strings
to clipboard fill and sendkeys ctrl-V
with a sleep 0.1 between
That seems to be working with very limited testing (you know, because its for work and it's Saturday).  More to tell next week.
Interesting side note: for the activity that was "Remote Meeting" I used the hotkey Ctrl+Alt+Shift+R
Oddly, and what I thought was unrelated, I discovered I had a ton of screencast files in the video folder.
Never heard of it, so researching it I learned it uses the same hotkey combo. Surprise.
Using Dconf-Editor I changed the hotkey for screencast. I bet that will have an impact on the reliability of that particular autokey script too.
Feeling much more confident now.

jos...@main.nc.us

unread,
May 5, 2022, 11:45:39 AM5/5/22
to autoke...@googlegroups.com


> Den ons 27 apr. 2022 kl 18:24 skrev <jos...@main.nc.us>:
>
>> Hi. This is a generic problem with slow applications that can't keep up
>> when AutoKey types at machine speed.
>>
>> The main offenders are LibreOffice and the Firefox address bar, but I
>> believe I've heard about Salesforce before as well.
>>
>
> Strange. I use it all the time in LibreOffice Calc and I'd say the
> problems
> there are very rare. Also, Autokey isn't needed very much in LibreOffice,
> because LibreOffice has its own customizable autocorrect feature (Tools →
> Autocorrect → Replace). You can even have different phrases in different
> languages and an overall one.
I have an AutoKey script that does a paste without formatting and formulas
that I use many times almost every day to save the previous value of a
computation (cell) in LO calc before entering updated data.

I'm glad if these problems have gone away. There haven't been any reports
of them in quite a while.
>
> In Firefox I almost never have any problem either. I'm writing this in
> Firefox right now and I almost insert my signature with AutoKey, and it
> never failed so far, as far as I remember. I use Autokey in the address
> bar
> too, and it usually works perfectly. Maybe it's a combination with
> software
> and hardware. Maybe I would have those problems on a slower computer, I
> don't know.
>
> Anyway, to be sure to never run into those rare occasions, I wrote a
> simple
> function for that. I guess others have done similar things and mine is
> probably not better than anyone else's, but here it is:
>
> def SendKeysSlowly(Text, Delay):
> for Character in Text:
> keyboard.send_keys(Character)
> time.sleep(Delay)
>
> Example how to use it:
> SendKeysSlowly("This text is typed slowly", 0.05)
> In this case, 0.05 means that there is a delay of 50 ms (0.05 seconds)
> between each character.
> Seems to work great and it looks cool too, if you pick the right delay… 😁
>
My version of this is in the wiki and there's a fancy version in the
comments to one of our issues.

Tip: If you define your function as

def SendKeysSlowly(Text, Delay=0.05):

then if you omit the delay parameter when you call it, it will default to
0.05.

Joe
>> https://groups.google.com/d/msgid/autokey-users/55a00f51516b85f8c24e7e1affe4e8b1.squirrel%40www.main.nc.us
>> .
>>
>
> --
> 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/CADo7T4dME3tAE0puqvrmeZxapQ%3DLyEe70rwPUezW1uXinPg2CQ%40mail.gmail.com.
>


jos...@main.nc.us

unread,
May 5, 2022, 11:53:25 AM5/5/22
to autoke...@googlegroups.com
Glad it's working for you now.

Unfortunately, each app and part of the desktop assigns whatever hotkeys
it wants to and there's no central hotkey database or utility so we have
to find the conflicts by trial and error. Using window filters in AutoKey
may reduce its contribution to the problem.

Joe
>>> https://groups.google.com/d/msgid/autokey-users/55a00f51516b85f8c24e7e1affe4e8b1.squirrel%40www.main.nc.us
>>> .
>>>
>>
>
> --
> 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/c9195c16-1efd-46fe-b415-a08b52405d6an%40googlegroups.com.
>


Reply all
Reply to author
Forward
0 new messages