pyVNC icon indicating copy to clipboard operation
pyVNC copied to clipboard

How to send key <ENTER> or user other defined keys?

Open damies13 opened this issue 3 months ago • 1 comments

Hi I would like to know how to send key <ENTER>?

I have tried the following but none of these worked:

  • vnc.send_key(KEY_KP_Enter)
  • vnc.send_key(KEY_Enter)
  • vnc.send_key('KEY_KP_Enter')
  • vnc.send_key('KEY_Enter')
  • vnc.send_key('\r')
  • vnc.send_key('\n')

I was able to send other keys (e.g. vnc.send_key('a')) just not any defined key

Note: I would have expected a KEY_Enter around line 40-50 in rfb.py.

Additional Info:

>>> vnc.send_key(KEY_KP_Enter)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'KEY_KP_Enter' is not defined


>>> vnc.send_key(KEY_Enter)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'KEY_Enter' is not defined


>>> vnc.send_key('KEY_KP_Enter')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py", line 31, in send_key
TypeError: ord() expected a character, but string of length 12 found


>>> vnc.send_key('KEY_Enter')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py", line 31, in send_key
TypeError: ord() expected a character, but string of length 9 found


>>> vnc.send_key(KEY_F1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'KEY_F1' is not defined


>>> vnc.send_key(KEY_BackSpace)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

My setup:

$ python
Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from PIL import Image
>>> import pyVNC.Client as VNCClient
/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py:61: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py:63: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py:65: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py:61: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py:63: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
/home/dave/venv/lib/python3.12/site-packages/pyVNC-0.1-py3.12.egg/pyVNC/Client.py:65: SyntaxWarning: "is" with 'str' literal. Did you mean "=="?
pygame 2.6.1 (SDL 2.28.4, Python 3.12.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> 
>>> import pygame
>>> 
>>> vnc = VNCClient.Client(host="192.168.13.231", port=6084, password=None, depth=32, fast=False, shared=True)
>>> 
>>> vnc.start()
>>> 

damies13 avatar Sep 28 '25 02:09 damies13

BTW vnc.get_screen() seems to be missing but I found a workable alternative, I figured out I could use this to get an image of the vcn screen and confirm the results of what I sent:

>>> 
>>> Image.frombytes('RGBA', vnc.screen.size, pygame.image.tostring(vnc.screen.canvas, 'RGBA')).show()
>>> 

damies13 avatar Sep 28 '25 02:09 damies13