[text] key1

Viewer

  1. #!/usr/bin/env python3
  2. import sys, select, tty, termios
  3. import rospy
  4. from std_msgs.msg import String
  5. if __name__ == '__main__':
  6.     key_pub = rospy.Publisher('keys', String, queue_size=1)
  7.     rospy.init_node("keyboard_driver")
  8.     rate = rospy.Rate(100)
  9.     old_attr = termios.tcgetattr(sys.stdin)
  10.     tty.setcbreak(sys.stdin.fileno())
  11.     print("Publishing keystrokes. Press Ctrl-C to exit...")
  12.     while not rospy.is_shutdown():
  13.         if select.select([sys.stdin], [], [], 0)[0] == [sys.stdin]:
  14.             key_pub.publish(sys.stdin.read(1))
  15.         rate.sleep()
  16.     termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_attr)

Editor

You can edit this paste and save as new:


File Description
  • key1
  • Paste Code
  • 17 Apr-2024
  • 643 Bytes
You can Share it: