Introducing the Morsecode_listener gem

#!/usr/bin/env ruby

# file: keypress_event.rb

require 'gtk2'
require 'morsecode'
require 'gtk2keypress'
require 'morsecode_listener' 


class MorseCodeTranslator < MorseCode

  def message(s)
    @input_string = s
    puts '>> ' + self.to_s
  end
end

mct = MorseCodeTranslator.new
mcl = MorseCodeListener.new notifier: mct

window = Gtk::Window.new
window.add(Gtk::Label.new("Press Key!"))

key = Gtk2KeyPress.new window, mcl

def key.on_keypress(e)
  puts 'key press ' + e.name
end

window.set_default_size(100, 100).show_all

Gtk.main

The above code demonstrates listening for key presses which is tapped out as Morse code, and is then tranlated to plain English.

It uses timing to differentiate between a dot, a dash, a separator, and a word. The default timings are as follows:

Resources