Sha256: 6a97cd8157483d5759bf26190d03b63d4b11071cc76f4d839eb16337383dd063
Contents?: true
Size: 1013 Bytes
Versions: 12
Compression:
Stored size: 1013 Bytes
Contents
class String # converts one-char string into keyboard-scan 'Virtual key' code # TODO: only letters and numbers convertible so far, need to extend further def to_key unless size == 1 raise "Can't convert but a single character: #{self}" end ascii = upcase.unpack('C')[0] # puts "I'm here with #{self}->#{ascii}" case self when 'a'..'z', '0'..'9', ' ' [ascii] when 'A'..'Z' [WinGui.const_get(:VK_SHIFT), ascii] when ',' [WinGui.const_get(:VK_OEM_COMMA)] when '.' [WinGui.const_get(:VK_OEM_PERIOD)] when ';' [WinGui.const_get(:VK_OEM_1)] when ':' [:VK_SHIFT, :VK_OEM_1].map {|s| WinGui.const_get s} when "\\" [WinGui.const_get(:VK_OEM_102)] when "\n" [WinGui.const_get(:VK_RETURN)] else raise "Can't convert unknown character: #{self}" end end def to_print force_encoding('cp1251').encode(Encoding.default_external, :undef => :replace) end end
Version data entries
12 entries across 12 versions & 1 rubygems