Skip to content

Instantly share code, notes, and snippets.

@cremno
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cremno/9113762 to your computer and use it in GitHub Desktop.
Save cremno/9113762 to your computer and use it in GitHub Desktop.
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