Skip to content

Instantly share code, notes, and snippets.

@mjdorma
Last active April 20, 2022 12:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjdorma/9132605 to your computer and use it in GitHub Desktop.
Save mjdorma/9132605 to your computer and use it in GitHub Desktop.
pyvbox: Register for decoded keystrokes
"""pyvbox: Register for decoded keystrokes
The following code will print key press events from the guest
VM to the host's stdout.
"""
import sys
import virtualbox
vbox = virtualbox.VirtualBox()
m = vbox.find_machine("win7")
s = m.create_session()
def callback(state, key):
if state == 1 and len(key) == 1:
sys.stdout.write(key)
sys.stdout.flush()
s.console.keyboard.register_key_callback(callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment