=begin #============================================================================== Title: Any Key Pressed Check Author: Hime Date: Nov 6, 2014 ------------------------------------------------------------------------------ ** Change log Nov 6, 2014 -initial release ------------------------------------------------------------------------------ ** Terms of Use * Free to use in commercial and non-commercial projects * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header ------------------------------------------------------------------------------ ** Description: This script provides a way for you to check whether a key is currently being pressed using a simple conditional check. ------------------------------------------------------------------------------ ** Installation Place this script below Materials and above Main ------------------------------------------------------------------------------ ** Usage To check whether any key is being pressed, use the script call Input.any_key_pressed? Which will return true if any keys are being pressed, and false otherwise. This may not work for input devices other than the keyboard. #============================================================================== =end $imported = {} if $imported.nil? $imported[:TH_AnyKeyPressedCheck] = true #============================================================================== # ** Rest of the script #============================================================================== module Input class << self alias :th_any_key_pressed_check_update :update end GetKeyboardState = Win32API.new("user32.dll", "GetKeyboardState", "I", "I") DOWN_STATE_MASK = (0x8 << 0x04) @state = DL::CPtr.new(DL.malloc(256), 256) # Not every key should be checked Keys_To_Check = 0.upto(255).to_a - [0x19] def self.update th_any_key_pressed_check_update GetKeyboardState.call(@state.to_i) @any_key_pressed = Keys_To_Check.any?{|key| @state[key] & DOWN_STATE_MASK == DOWN_STATE_MASK} end def self.any_key_pressed? @any_key_pressed end end