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
  Unable to understand the meaning of the line of code. jahuja73 0 303 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,663 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 722 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  Help Switching between keyboard/Mic input in my code Extra 1 1,087 Aug-28-2022, 10:16 PM
Last Post: deanhystad
  (OpenCV) Help to improve code for object detection and finding center of it saoko 0 1,203 May-14-2022, 05:34 PM
Last Post: saoko
  Correct the algorithm of image filter code saoko 6 2,003 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 2,399 Feb-13-2022, 07:13 PM
Last Post: menator01
  Help me with Image detection GoA_TrancE 1 1,999 Oct-18-2021, 02:03 PM
Last Post: GoA_TrancE
  code decode, string, image ... teckow 2 2,054 Aug-20-2021, 07:02 PM
Last Post: teckow
  how long can a line of code be? Skaperen 2 2,210 Jun-09-2021, 06:31 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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