Need help to change keydown() code because this is not working, even I have to run it via batch file (with Admin Rights)

Asked by sami baig on 2017-12-28

I want to convert below code with write() function:

KeyDown(Key.ALT)
type(Key.TAB)
keyUp()

I have edited these attributes in write() function but it is not working with it:

number_ of_lines = 2
write("#W5#A+#T%d#A-"%number_of_lines)

[Error] NameError ( name 'key' is not defined)

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2017-12-28
Last query:
2017-12-28
Last reply:
2017-12-28
Best RaiMan (raimund-hocke) said : #1

I have to check, whats wrong with write() (Be aware: not yet official ;-)

this worked for me:

number_of_lines = 2
for i in range(number_ of_lines): type(Key.TAB, Key.ALT)

... is a one-liner too ;-)

sami baig (gabbarmic) said : #2

But it is also giving 'SyntaxError("no viable alternative at input 'i'",) :-)

sami baig (gabbarmic) said : #3

Error stated as 'SyntaxError("no viable alternative at input 'range'",)

RaiMan (raimund-hocke) said : #4

there was a typo in your code and I did copy&paste ;-)
number_ of_lines has a space before the o - must be
number_of_lines

BTW: I prefer CamelCase: numberOfLines

sami baig (gabbarmic) said : #5

Again type and now giving error 'mismatch input 'type' expecting INDENT",) on following code: :@

numbeOfLines = 2
for I in range (njmberOfLines):
Type(Key.TAB, Key.ALT)

RaiMan (raimund-hocke) said : #6

ok, that is Python knowledge.
you need at least a little bit of it.
only copy&paste does lead too far

numbeOfLines = 2
for I in range (numberOfLines):
    type(Key.TAB, Key.ALT)

sami baig (gabbarmic) said : #7

Oh, I didn't check that, I excuse for this =|

sami baig (gabbarmic) said : #8

Thanks RaiMan, that solved my question.