Skip to content

Instantly share code, notes, and snippets.

@hako
Forked from alyssais/httppp.rb
Last active August 29, 2015 14:07
Show Gist options
  • Save hako/53d47055f4db164b7777 to your computer and use it in GitHub Desktop.
Save hako/53d47055f4db164b7777 to your computer and use it in GitHub Desktop.
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