Skip to content

Instantly share code, notes, and snippets.

@hako
Forked from alyssais/httppp.rb
Last active Aug 29, 2015
Embed
What would you like to do?
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