Skip to content

Instantly share code, notes, and snippets.

@jeremywrnr
Created September 8, 2016 17:43
Show Gist options
  • Save jeremywrnr/3bf4da8353c3702de23df5842a5fb0d7 to your computer and use it in GitHub Desktop.
Save jeremywrnr/3bf4da8353c3702de23df5842a5fb0d7 to your computer and use it in GitHub Desktop.
Pipe serial monitor output to OSX keyboard
# using the SerialPort gem, rout serial input to OSX keyboard
require 'serialport'
require 'accessibility/keyboard'
include Accessibility::Keyboard
# params for serial port, may be different for you
port = '/dev/cu.usbmodem1421'
SerialPort.open(port) do |sp|
# configure port
sp.baud = 9600
sp.data_bits = 8
sp.stop_bits = 1
sp.parity = SerialPort::NONE
sp.read_timeout = 200
# rout data to keyboard
while true do
inbyte = sp.gets
next if inbyte.nil?
keyboard_events_for(inbyte.chomp).each {|e| KeyCoder.post_event(e) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment