-
-
Save hako/53d47055f4db164b7777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
require 'sinatra' | |
def keycode(key) | |
name = "VK_#{key.upcase}" | |
java.awt.event.KeyEvent.const_get(name) | |
end | |
robot = java.awt.Robot.new | |
BUTTONS = %w[ | |
up down left right | |
a b start select | |
] | |
BUTTONS.each do |button| | |
post "/api/v1/moves/#{button}" do | |
code = keycode case button | |
when :select then ?q | |
when :start then 'enter' | |
when :a then ?s | |
when :b then ?a | |
else button | |
end | |
robot.keyPress(code) | |
sleep 0.1 | |
robot.keyRelease(code) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment