sibson / vncdotool

A command line VNC client and python library
Other
458 stars 123 forks source link

"type" not working with python code #285

Closed TejasPatadiya10 closed 7 months ago

TejasPatadiya10 commented 7 months ago

I am using python 3.11 with vncdotool and following is my code

client = api.connect('server')
client.keyPress('enter')
client.captureScreen('screenshot.png')
client.type('cmd')

I am getting below error on client.type('cmd'):

  Message=type object 'VNCDoToolClient' has no attribute 'type'
    client.type('cmd')
    ^^^^^^^^^^^
AttributeError: type object 'VNCDoToolClient' has no attribute 'type'
pmhahn commented 7 months ago

Because VNCDoToolClient does not have a method named type;

type is a command implemented by only by the CLI wrapper vncdotool.command.

If you want to use the API directly yourself, see documenation using client.keyPress(…).

TejasPatadiya10 commented 7 months ago

Hey ,

Thanks for looking into it.

As per your suggestion of keypress , i tried below :

client = api.connect('server') client.keyPress('enter') client.captureScreen('screenshot.png') client.keyPress('cmd')

but it again gives me error:

ord() expected a character, but string of length 3 found

I wanted to open command prompt and run commands in another machine using VNC Session , can anyone please help me out ?

Thanks

pmhahn commented 7 months ago

Again: RTFM! keyPress works on single keys, e.g. a single character. To type a string you have to press multiple keys.

And be warned: there is not a single mapping from "character" to "key": to type some characters you have to press Shift/Alt/Ctrl/Compose/… keys before pressing a key and then releasing them again in the (correct) order. That is a deficiency of VNC; see https://github.com/sibson/vncdotool/issues/269#issuecomment-1696847993 for details