forked from yuvaramsingh94/Ros-Keyboard-Input
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeypress.py
31 lines (25 loc) · 1006 Bytes
/
keypress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
import getch
import rospy
from std_msgs.msg import String #String message
from std_msgs.msg import Int8
################################
# created by yuvaram
#yuvaramsingh94@gmail.com
################################
def keys():
pub = rospy.Publisher('waypoint/keypress',Int8,queue_size=10) # "keypress" is the publisher name
rospy.init_node('keypress',anonymous=True)
rate = rospy.Rate(10) # try removing this line ans see what happens
while not rospy.is_shutdown():
k=ord(getch.getch()) # this is used to convert the keypress event in the keyboard or joypad , joystick to a ord value
if (k==32): # to filter only the space key /// this line can be removed or more key can be added to this
rospy.loginfo(str(k)) # to print on terminal
pub.publish(k) # to publish
# rospy.loginfo(str(k))
# rate.sleep()
if __name__=='__main__':
try:
keys()
except rospy.ROSInterruptException:
pass