autokey / autokey

AutoKey, a desktop automation utility for Linux and X11.

Home Page:https://autokey.github.io/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

highlevel.click_on_pat Often Fails With no images defined `png:/tmp/somernd`

dginovker opened this issue · comments

commented

AutoKey is a Xorg application and will not function in a Wayland session. Do you use Xorg (X11) or Wayland?

Xorg

Has this issue already been reported?

  • I have searched through the existing issues.

Is this a question rather than an issue?

  • This is not a question.

What type of issue is this?

Bug

Choose one or more terms that describe this issue:

  • autokey triggers
  • autokey-gtk
  • autokey-qt
  • beta
  • bug
  • critical
  • development
  • documentation
  • enhancement
  • installation/configuration
  • phrase expansion
  • scripting
  • technical debt
  • user interface

Other terms that describe this issue if not provided above:

highlevel

Which Linux distribution did you use?

Arch Linux x86_64

Which AutoKey GUI did you use?

Qt

Which AutoKey version did you use?

Latest git (May 6th, 2023)

How did you install AutoKey?

Git

Can you briefly describe the issue?

With the following code:

path = "/home/xacket/.config/autokey/data/myimage.png"

# try to click the image, catch and print the error if it fails
try:
  autokey.scripting.highlevel.click_on_pat(path, 1, (50, 50), 32000)
except Exception as e:
  print("Didn't find {} on the screen".format(path))

I often see

X Error of failed request:  BadColor (invalid Colormap parameter)
  Major opcode of failed request:  91 (X_QueryColors)
  Resource id in failed request:  0x0
  Serial number of failed request:  456
  Current serial number in output stream:  456
convert: unable to read image header `-' @ error/xwd.c/ReadXWDImage/227.
convert: no images defined `png:/tmp/tmp1s6e_yoa' @ error/convert.c/ConvertImageCommand/3342.
Didn't find /home/xacket/.config/autokey/data/myimage.png on the screen

Can the issue be reproduced?

Sometimes

What are the steps to reproduce the issue?

  1. Put the above code in Autokey
  2. Save an image at the path, make sure the image is on the screen
  3. Assign a hotkey to the script
  4. Hit the hotkey

What should have happened?

The image should be clicked

What actually happened?

For random periods of 60 seconds it works, then it doesn't

Do you have screenshots?

No response

Can you provide the output of the AutoKey command?

No response

Anything else?

It seems to not work after editing hotkey scripts recently, but then starts working later? Really not sure. Also I'm editing the hotkey scripts external to the built-in editor, but I can't imagine that's related.

Many thanks for Autokey!

commented

As much as I keep promoting this feature, no one seems to use it, so we have very little experience with it. I think this is its first ever reported bug.

We could really use some input from people such as yourself who are actually using it - on Gitter and with anything you want to add to our wiki and examples.

Hopefully, one of our devs can take a look at this. (We are very short on developer resources.)

Although I think this is a killer feature that really should get used a lot, I would caution developers not to rely on it too heavily. The Xautomation project has been inactive for several years and it is very unlikely to work with Wayland. (Currently, AutoKey doesn't work with Wayland either, but we're working on that.)

I've got no experience with using the highlevel API calls, but I took a look at the documentation for the autokey.scripting.highlevel.click_on_pat() call.

When looking at this line in your code, I noticed that you're missing the restore_pos part of the call, so perhaps AutoKey is getting lost since it hasn't been returned to the initial mouse position after the click:

autokey.scripting.highlevel.click_on_pat(path, 1, (50, 50), 32000)

That might explain why it sometimes works and sometimes doesn't, since it stands to reason that it would sometimes be in the starting position, but other times wouldn't.

commented

restore_pos defaults to false.

In Python, defining function arguments is a big deal. This article is amazingly clear and detailed.

I'm not sure, but I think the way the API function call was coded is probably fine.
(That article was a lot to absorb at one time!)

What the heck does a tolerance of 32000 do? I see the definition of tolerance, but not what the values actually mean.

restore_pos defaults to false.

My point, exactly.

What the heck does a tolerance of 32000 do? I see the definition of tolerance, but not what the values actually mean.

I'm not sure, but I'm guessing it means that it has a very high tolerance for fuzzy matches. I've done something similar in CSS, where you can set different tolerances. When you want to be sure that one of the things you're setting tolerances for always takes precedence, you just give it a ridiculously-high number.