kaspergrubbe / ruby-vnc

A library for interaction automation of servers via VNC
MIT License
31 stars 17 forks source link

supported direct specification with key code #24

Closed lobin-z0x50 closed 5 years ago

lobin-z0x50 commented 5 years ago

I want to specify the key code directly from my program and perform the key operation.

kaspergrubbe commented 5 years ago

Looks good, but how about we rewrite it to a case statement, it makes it a bit prettier I think.


def get_key_code which
  case which
  when String
    if which.length != 1
      raise ArgumentError, 'can only get key_code of single character strings'
    end
    which[0].ord
  when Symbol
    KEY_MAP[which]
  when Integer
    which
  else
    raise ArgumentError, "unsupported key value: #{which.inspect}"
  end
end