Skip to content

Instantly share code, notes, and snippets.

@alyssais
Created October 8, 2014 21:18
Show Gist options
  • Save alyssais/2948cc90ae1298592b1e to your computer and use it in GitHub Desktop.
Save alyssais/2948cc90ae1298592b1e to your computer and use it in GitHub Desktop.
HTTP Plays Pokémon!
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