capture image automatically in a specific location

Asked by rekem killei

I'm trying to create a game-bot and I ran into a couple of problems:
1: is there a way to hold a key down for a minute?
2: is there a way to capture an image in a specific location and convert it to text (automatically)

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
rekem killei (botko) said :
#1

anyone?

Revision history for this message
rekem killei (botko) said :
#2

please help

Revision history for this message
RaiMan (raimund-hocke) said :
#3

- use latest version 1.1.1 (http://sikulix.com)
- read the docs

at 1: see low-level mouse and keyboard actions (down-wait-up)

at 2: the OCR feature has many problems, so first try, wether it works with your images (faq 2436)

If the built-in OCR is not sufficient, you might try to save the capture as image file and use the Tesseract package standalone.

There are many methods to exactly define a Region on the screen, that should be used to "be converted to text"

Revision history for this message
rekem killei (botko) said :
#4

keyDown(Key.SHIFT) does not seem to work for me at all... and even if it did I still don't understand how to limit it to 1 min
can you post an example of a code that holds a key for a minute?

can you post an example of a code that captures an image in a specific place automatically?

Thank you very much for helping me @RaiMan

Revision history for this message
rekem killei (botko) said :
#5

edit: Understood how to capture image in a specific location now I only need to know how to hold a key for a minute (or old a key at all because keyDown doesnt work for me)

Revision history for this message
masuo (masuo-ohara) said :
#6

This is one way to act something after certain duration.
In this case, action is keyUp().

import thread
import datetime

def actsomething(name,*arg):
    print datetime.datetime.now()
    cnt = arg[0]
    while cnt > 0:
        cnt = cnt -1
        sleep(1)
    keyUp(Key.SHIFT)
    print datetime.datetime.now()

duration = 5 # 5sec
thread.start_new_thread(actsomething,("funcname",duration))
keyDown(Key.SHIFT)

for i in range(10):
    type("a")
    sleep(1)

Revision history for this message
RaiMan (raimund-hocke) said :
#7

@masuo: he did not say, that he wants to do something else in parallel, while he holds shift down.

So the answer to his question would be:
keyDown(Key.SHIFT)
wait(60)
KeyUp()

... and even if he wants to do something else after keyDown():
(module time is already imported in SikuliX)

end = time.time() + 60
keyDown(Key.SHIFT)

# do something else

while time.time() < end: wait(1)
keyUp()

Revision history for this message
RaiMan (raimund-hocke) said :
#8

@rekem
How do you know, that keyDown(Key.SHIFT) does not work?

a simple test:
take care, that some editor window is the frontmost application or something else, that accepts input.

keyDown(Key.SHIFT)
type("a")
KeyUp()

should enter an uppercase A

If this works, then the most probable cause for a not-working keyDown() is that the game blocks non-human keyboard actions.
Try to run the IDE or the script as admin.

Revision history for this message
rekem killei (botko) said :
#9

Tried it all. it still does not seem to hold the key only to press it every 1 second

Revision history for this message
RaiMan (raimund-hocke) said :
#10

what about the test suggestion in comment #8?

BTW: what system?

Revision history for this message
TestMechanic (ndinev) said :
#11

Just saw the question and can confirm that this code:

print "You have 3 seconds to focus notepad"
sleep(3)
keyDown(Key.SHIFT)
type("a")
keyUp()

works fine on Windows 10, Mac Os ElCapitan and Lubuntu 16.04

Revision history for this message
Launchpad Janitor (janitor) said :
#12

This question was expired because it remained in the 'Needs information' state without activity for the last 15 days.