Python Forum
I need a code line to spam a keyboard key | Image detection bot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need a code line to spam a keyboard key | Image detection bot
#1
Hello, first of all I`m a complete noob. I followed a tutorial and made this so far. This detects a small icon 40x40 in size on my screen and it works great even if I block the icon by 50%.

"all" I need is a code line to spam a keyboard key after the bot sees the image.



Here is my code:

from pyautogui import *

import pyautogui

import time

import keyboard

import random

import win32api, win32con



while 1:

if pyautogui.locateOnScreen('ircr.png', region=(300,700,400,400) , grayscale=True, confidence=0.8) != None:

print("I can see it")

time.sleep(0.5)

else:

print("I am unable to see it")

time.sleep(0.5)
Reply
#2
Ok I found out how to press the key I want to. But simply adding the line to my code does not press the keyboard key. I need my bot to hit a key after he sees the image.

I`m missing a key link between the two.

update:

while 1:
if pyautogui.locateOnScreen('ircr.png', region=(300,700,400,400) , grayscale=True, confidence=0.8) != None:
print("I can see it")
time.sleep(0.5)
else:
print("I am unable to see it")
time.sleep(0.5)


pyautogui.press('esc', presses=2)
Reply
#3
solved :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem When using canny edge detection,black image returned rickyw2777 1 453 Feb-17-2025, 03:22 AM
Last Post: rickyw2777
  QR code creation with image Raja31 1 802 Jan-15-2025, 11:17 AM
Last Post: Larz60+
  Printing the code line number arbiel 6 1,629 Jun-30-2024, 08:01 AM
Last Post: arbiel
  Unable to understand the meaning of the line of code. jahuja73 0 1,026 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 2,789 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 1,216 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  Help Switching between keyboard/Mic input in my code Extra 1 1,860 Aug-28-2022, 10:16 PM
Last Post: deanhystad
  (OpenCV) Help to improve code for object detection and finding center of it saoko 0 2,034 May-14-2022, 05:34 PM
Last Post: saoko
  Correct the algorithm of image filter code saoko 6 3,362 May-08-2022, 05:06 PM
Last Post: saoko
  Python code to read second line from CSV files and create a master CSV file sh1704 1 3,496 Feb-13-2022, 07:13 PM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020