Skip to content

Instantly share code, notes, and snippets.

@cremno

cremno/joystick.rb

Last active Aug 29, 2015
Embed
What would you like to do?
Joystick
# ★ Joystick
# ★★★★★★★★
#
# Author/s : cremno
# RGSS ver : 1 to 3
module Joystick
class << self
def uint(v)
v & 0xffff_ffff
end
private :uint
def number_of_devices
uint(Win32API.new('winmm', 'joyGetNumDevs', 'V', 'I').call)
end
def position(id = 0)
f = Win32API.new('winmm', 'joyGetPos', 'IP', 'I')
ji = "\0" * 16
[
uint(f.call(id, ji)),
ji.unpack('I4')
]
end
def attached?
number_of_devices != 0 && position[0] == 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.