Last active
August 29, 2015 13:56
-
-
Save cremno/9113762 to your computer and use it in GitHub Desktop.
Joystick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ★ 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