Backspace x 10

Asked by Steen

Hi There

Im new to Sikuli and like the Crossplatform tool!
i have been using Autohotkey which is PC only.

I have a gui where i have to delete the last entry in a text box.
the text box does not support right click or any thing i have to press backspace like 30 times.

how do i do:
type(Key.BACKSPACE) x 30

instead of:
type(Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE + Key.BACKSPACE)

thanks in advance..:0)

Steen

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Steen
Solved:
Last query:
Last reply:

This question was reopened

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

2 of many solutions ;-)

--1.
def myMulti(n, k = Key.BACKSPACE):
     for i in range n:
         type(k)

# usage:
myMulti(30)) # 30 backspaces
myMulti(10, Key.DOWN) # 10 down's

--2:
def myMulti(n, k = Key.BACKSPACE):
     r = k
     for i in range n-1:
         k += Key.BACKSPACE)
     return r

# usage
type(myMulti(30)) # 30 backspaces
type(myMulti(10, Key.DOWN)) # 10 down's

Revision history for this message
Steen (steenc) said :
#2

ok, it makes some sense but not enough, im new to this language...:0)

is ther a more simple solution.

none of those worked, or do i have to fill anything in

Revision history for this message
Steen (steenc) said :
#3

acidently hit the solved button....not good....!...

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

Sorry for mistyping in the for statements :-(

Now I tested the stuff and found, that only --1. works as expected (with --2. the backspaces seem to come to fast after each other)

so again:

1 of some solutions ;-)

--1.
def myMulti(n, k = Key.BACKSPACE):
     for i in range(n):
         type(k)

# usage:
myMulti(30)) # 30 backspaces
myMulti(10, Key.DOWN) # 10 down's

Only to be sure:
the focus has to be on the text field and the cursor posited correctly.

Revision history for this message
Steen (steenc) said :
#5

click(Pattern("Updatefuldcr.png").targetOffset(79,24))
def myMulti(n, k = Key.BACKSPACE):
      for i in range(n):
          type(k)

# usage:
 myMulti(30)) # 30 backspaces
 myMulti(10, Key.DOWN) # 10 down's

i get:
error] Error message: IndentationError: ('unindent does not match any outer indentation level', ('C:\\Users\\X86_Win7\\AppData\\Local\\Temp\\sikuli-tmp5544661324136042328.py', 11, 1, ' myMulti(30)) # 30 backspaces\n'))

your help is appreciated, thank you very much.

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

ok, this is one of the most frustrating things for newcomers regarding the Python language :-(

aaaarrrrggghhh !!!!! indentation error ***???***

indentation is the tool in Python to build blocks of statements, that belong together (e.g. the body of a function or a loop). dedentation marks the next statement, that does not belong to the block any more, but it has to match any indentation of an outer block, that was used before.
Sounds complicated, but is not. In other languages you usually use some bracketing instead.

So lets try to learn something from the error message:

-- where did it happen?

11, 1, ' myMulti(30)) # 30 backspaces\n'

it is line 11 character position 1

-- what is wrong?
IndentationError: ('unindent does not match any outer indentation level'

It is not possible, to evaluate, to which block this statement belongs, since it starts with a blank (no other statement before starts with an indent of one blank!)

so get rid of the blank.

all statements on block level 0 (the script level) have to be left justified!

-- TIP: only use tab/shift-tab to indent dedent. A tab is converted to 4 spaces automatically and shift-tab deletes 4 spaces from the beginning of the line.

-- BTW:
# usage:
myMulti(30)) # 30 backspaces
myMulti(10, Key.DOWN) # 10 down's

only wanted to show the 2 different usage possibilities.

*** So your case:

# functions should be placed at the beginning of the script
def myMulti(n, k = Key.BACKSPACE):
      for i in range(n):
          type(k)

click(Pattern("Updatefuldcr.png").targetOffset(79,24))
myMulti(30)) # 30 backspaces

Revision history for this message
Steen (steenc) said :
#7

ok, thanks
this works:
def myMulti(n, k = Key.BACKSPACE):
       for i in range(n):
           type(k)
click(Pattern("Updatefuldcr.png").targetOffset(79,24))
myMulti(30, Key.BACKSPACE)