No commit activity in last 3 years
No release in over 3 years
Use in conjunction with an event driven application to listen for a morse code message.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

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 are tapped out as Morse code, and is then translated to plain English.

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

  • dot: < 0.35 second
  • dash: < 1 second
  • separator: <= 0.7 second
  • word separator: 1.35 seconds

Resources

morsecode keypress gtk2