[1.1.4]How to print Key.ENTER name?

Asked by Linda

I want to print(Key.ENTER)
then result is
ENTER

print(Key.DELETE)
the result is
DELETE

I try to Key.ENTER.__name__
There is error message: unicode object no "name" attribute

how to print key's name?

Question information

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

This question was reopened

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

I do not understand???

ENTER and DELETE are the names of the keys.

Or what do you mean by name?

Revision history for this message
Linda (kkea55534) said :
#2

I def a function:
def RecordLog(KEY):
    type(KEY)
   os.system(r'echo' + type.__name__ + str(KEY) + r'>>' + Log)

But the result is not name.

For example:
Refer to :https://inventeccorp-my.sharepoint.com/:i:/g/personal/huang_linda_inventec_com/EbslPjdskOBMpgjWaCXhoX0BpWxiYuidYCemfBXDmyEXEw?e=PW76Wq

The result of print(Key.ENTER) is not ENTER but a blank.

Then try Key.DELETE: https://inventeccorp-my.sharepoint.com/:i:/g/personal/huang_linda_inventec_com/EfuTHlINS75EkrZQmfIcfMABJwgnkAKsxd1F0pkOIn_YrA?e=Nd3fEb

How to print their name to log ?

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

The only solution I can offer:

def RecordLog(KEY):
    type(KEY)
    KEYname = Key.toJavaKeyCodeText(KEY)
    Log = "path-to-LogFile"
    os.system('echo type(%s) >>%s' % (KEYname, Log))

Key.XXX are internal non-printable binary codes

Revision history for this message
Linda (kkea55534) said :
#5

Hi,RaiMan
I try with KEY_CTRL

show: toJavaKeyCodeText(): 1st arg can't be coerced to char

How to print its name?

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

use Key.CTRL

Revision history for this message
Linda (kkea55534) said :
#7

Thanks RaiMan, that solved my question.