Skip to main content

This is a wrapper around win32api, pyautogui and pynput.

Project description

RazbiUtils

This package is a wrapper around win32api, pyautogui and pynput intended for ScreenScraping.

pip install RazbiUtils

RazbiUtils supports at least python 3.6 and I've tested it only on windows. No guarantee that will work on linux.

The API is designed to be similar to pyautogui, but to fix a lot of the issues pyautogui has.

The first issue it solves is the mouse input, by using internally pynput for mouse clicks and keyboard keys, this assures that all the programs/games will receive the input. Which wasn't a problem for chrome, but it was on many other random programs.

The second issue was both the click speed and the screenshot speed. The click speed was fixed once again by pynput and for the screenshot I used something written using win32api by Frannecklp [Here's a link to the origin of the screenshot https://pythonprogramming.net/next-steps-python-plays-gta-v/]

The third issue I attempt to solve is to make it work for multiple monitors and to make the coordinate system easier, by letting you specify portions of the screen without specific coordinates. I've fixed this by detecting the monitors using win32api and organising it.

Examples

Basic template detection

from RazbiUtils import ScreenScraper

sc = ScreenScraper()

path_to_template = 'object_to_detect'
if sc.find_on_screen_bool(path_to_template):
    print("Object Detected")

Assuming that you have a path to an actual .png that it's on the main screen right now. The script should be able to detect it. [For managing template images, I strongly recommend paint.net https://www.dotpdn.com/downloads/pdn.html as it's free, easy to use and lighweight]

Ok, but let's make a little more interesting: let's make it click on the found object:

from RazbiUtils import ScreenScraper, InputController

sc = ScreenScraper()

path_to_template = 'object_to_detect'
found = sc.find_on_screen(path_to_template)
if found:
    print(f"Object Detected at {found[0]}")
    InputController.click(sc.center(found[0]))

Object Detected at Box(left=1590, top=951, width=189, height=54)

Note that I use found[0] instead of just found, because the screenshot by default returns a list of all found objects, [0] being the first. Also note that you if you don't use sc.center(), you'll use only the top-left of the detected image.

Multi-monitor support:

Let's say you want to screenshot something visible on your second monitor, pyautogui is normally unable to do this, but with RazbiUtils you just do:

from RazbiUtils import ScreenScraper, ScreenManager

sc = ScreenScraper()

path_to_template = 'object_to_detect'
if sc.find_on_screen_bool(path_to_template, ScreenManager.screens[1]):
    print("Object Detected")

The order of the screens are basically, the order you set in the OS.

Also if you want to screenshot just specific parts to make the screenshot fast without actual coordinates you can do: ScreenManager.screens[0].bottom_right for just the bottom right. Also you can do ScreenManager.main_screen which is equivalent with ScreenManager.screens[0]

Note: You can also instantiate ScreenManager if you want to reference it in a shorter form like sm

Mouse clicks support on ANY app

I'm referring to just clicks, mouse movements won't work certainly. Keep in mind that internally it uses pynput for clicks, so if you just want that, just use pynput.

The InputController.click() has a parameter for framerate by default 60. That means the delay between clicks is 1/60 which is 0.016, which will guarantee it will register the click if the app is 60fps.

For some reason the pyautogui clicks don't work on most games, so feel free to use this library or pynput for clicks

Support

If you have any suggestions, please make a pull request, so far I added only features I use really often for ScreenScraping, but I'm sure I haven't covered everything that's being used by everyone.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

RazbiUtils-0.0.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

RazbiUtils-0.0.3-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file RazbiUtils-0.0.3.tar.gz.

File metadata

  • Download URL: RazbiUtils-0.0.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for RazbiUtils-0.0.3.tar.gz
Algorithm Hash digest
SHA256 59881104c459c411a85a2843dd345d2ed6b2d775538ca05238c9d73ab76152d9
MD5 473b5f676efaf17fb33e6aa465b9f2fd
BLAKE2b-256 ecc091d744e46d1b8f876d643b813c96bc989c47d6f99bf677e4e89a434db6c0

See more details on using hashes here.

File details

Details for the file RazbiUtils-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: RazbiUtils-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for RazbiUtils-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1ea9a7c0c3f1a3ca435ca9b15e52c64bbdba7a9f885dcd7d693eaaf773cba1bb
MD5 ed3128e7c7abc36576a531fd850e12c3
BLAKE2b-256 e169d0bedea2c4fb1d4155d93230f8932afea1bce5496118483cd16126f06e2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page