Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Leon

[RGSS]Key Input Script by Cybersam

Recommended Posts

Okay, this is more of a scripter's tool than a tool for everyone. This script by Cybersam allows key input with ANY key on the keyboard. (if you ask where the ANY key is, Ark, I'll locate and nullify you.) Now, to use this script, insert the module and core script into your game, and in the scene where you want to use any key; use the command:

Keyboard.update

in the loop where it updates the graphics. I also recommend removing the Input.update when using this; replacing all of the original input buttons.

 

Now, to use a key, you use this format:

if Keyboard.trigger(Keys::A)

which, in this case, tells you the 'a' key was pressed.

	Graphics.transition
loop do
  Graphics.update
  Keyboard.update
  update
  if $scene != self
	break
  end
end
Graphics.freeze

Like that. Now, as for the script(s):

module Keys

 NULL   = 0x00		# NULL Value


 MOUSE_LEFT   = 0x01		# left mouse button
 MOUSE_RIGHT  = 0x02		# right mouse button
 MOUSE_MIDDLE = 0x04		# middle mouse button

 BACK	  = 0x08		# BACKSPACE key
 TAB	   = 0x09		# TAB key
 RETURN	= 0x0D		# ENTER key
 SHIFT	 = 0x10		# SHIFT key
 PAUSE	 = 0x13		# PAUSE key
 ESCAPE	= 0x1B		# ESC key
 SPACE	 = 0x20		# SPACEBAR

 PAGEUP	= 0x21		# PAGE UP key
 PAGEDOWN  = 0x22		# PAGE DOWN key
 END_	  = 0x23		# END key
 HOME	  = 0x24		# HOME key

 UP	 = 0x26		# UP ARROW key
 DOWN   = 0x28		# DOWN ARROW key
 LEFT   = 0x25		# LEFT ARROW key
 RIGHT  = 0x27		# RIGHT ARROW key

 SELECT	= 0x29		# SELECT key
 PRINT	 = 0x2A		# PRINT key
 SNAPSHOT  = 0x2C		# PRINT SCREEN key
 INSERT	= 0x2D		# INS key
 DELETE	= 0x2E		# DEL key

 N_0		 = 0x30		# 0 key
 N_1		 = 0x31		# 1 key
 N_2		 = 0x32		# 2 key
 N_3		 = 0x33		# 3 key
 N_4		 = 0x34		# 4 key
 N_5		 = 0x35		# 5 key
 N_6		 = 0x36		# 6 key
 N_7		 = 0x37		# 7 key
 N_8		 = 0x38		# 8 key
 N_9		 = 0x39		# 9 key

 A		 = 0x41		# A key
 B		 = 0x42		# B key
 C		 = 0x43		# C key
 D		 = 0x44		# D key
 E		 = 0x45		# E key
 F		 = 0x46		# F key
 G		 = 0x47		# G key
 H		 = 0x48		# H key
 I		 = 0x49		# I key
 J		 = 0x4A		# J key
 K		 = 0x4B		# K key
 L		 = 0x4C		# L key
 M		 = 0x4D		# M key
 N		 = 0x4E		# N key
 O		 = 0x4F		# O key
 P		 = 0x50		# P key
 Q		 = 0x51		# Q key
 R		 = 0x52		# R key
 S		 = 0x53		# S key
 T		 = 0x54		# T key
 U		 = 0x55		# U key
 V		 = 0x56		# V key
 W		 = 0x57		# W key
 X		 = 0x58		# X key
 Y		 = 0x59		# Y key
 Z		 = 0x5A		# Z key

 LWIN	  = 0x5B		# Left Windows key (Microsoft Natural keyboard) 
 RWIN	  = 0x5C		# Right Windows key (Natural keyboard)
 APPS	  = 0x5D		# Applications key (Natural keyboard)

 NUM_0   = 0x60		# Numeric keypad 0 key
 NUM_1   = 0x61		# Numeric keypad 1 key
 NUM_2   = 0x62		# Numeric keypad 2 key
 NUM_3   = 0x63		# Numeric keypad 3 key
 NUM_4   = 0x64		# Numeric keypad 4 key
 NUM_5   = 0x65		# Numeric keypad 5 key
 NUM_6   = 0x66		# Numeric keypad 6 key
 NUM_7   = 0x67		# Numeric keypad 7 key
 NUM_8   = 0x68		# Numeric keypad 8 key
 NUM_9	 = 0x69		# Numeric keypad 9 key

 NUM_MULTIPLY  = 0x6A		# Multiply key (*)
 NUM_ADD	   = 0x6B		# Add key (+)
 NUM_SEPARATOR = 0x6C		# Separator key
 NUM_SUBTRACT  = 0x6D		# Subtract key (-)
 NUM_DECIMAL   = 0x6E		# Decimal key
 NUM_DIVIDE	= 0x6F		# Divide key (/)

 CAPSLOCK  = 0x14		# CAPS LOCK key

 SEMI_COLON = 0xBA		#Semi-colon Key (;)
 EQUAL = 0xBB			 #Equal Key (=)
 COMMA = 0xBC			 #Comma Key (,)
 DASH = 0xBD			  #Dash Key (-)
 PERIOD = 0xBE			#Period Key (.)
 SLASH = 0xBF			 #Slash Key (/)
 ACCENT = 0xC0			#Accent Key (`)
 OPEN_BRACKET = 0xDB	  #Open Bracket ([)
 F_SLASH = 0xDC		   #Forward Slash (\)
 CLOSE_BRACKET = 0xDD	 #Close Bracket (])
 QUOTE = 0xDE		#Open Quote (')

 F1		= 0x70		# F1 key
 F2		= 0x71		# F2 key
 F3		= 0x72		# F3 key
 F4		= 0x73		# F4 key
 F5		= 0x74		# F5 key
 F6		= 0x75		# F6 key
 F7		= 0x76		# F7 key
 F8		= 0x77		# F8 key
 F9		= 0x78		# F9 key
 F10	   = 0x79		# F10 key
 F11	   = 0x7A		# F11 key
 F12	   = 0x7B		# F12 key

 NUMLOCK   = 0x90		# NUM LOCK key
 SCROLLOCK = 0x91		# SCROLL LOCK key

 L_SHIFT	  = 0xA0		# Left SHIFT key
 R_SHIFT	  = 0xA1		# Right SHIFT key
 L_CONTROL  = 0xA2		# Left CONTROL key
 R_CONTROL  = 0xA3		# Right CONTROL key
 L_ALT	  = 0xA4		# Left ALT key
 R_ALT	  = 0xA5		# Right ALT key
end

#==============================================================================
#
# Keyboard Script v3									  created by: cybersam
#
# its a small update...
# this have a script in it that allows you to insert a text with the keyboard
# inside the game... scroll down the script lit and you'll see it ^-^
# there is a new event on the map that shows you how it works...
# you can use the variables and command in the event in a script as well 
# since it works with "call script"
# now then... have fun with it ^-^
#
#==============================================================================
#
# hi guys.... it me again... ^-^
#
# now... this script is for more keys to press...
# anyone you like...
#
# mostly all keys are added...
#
# this version is now as module and easier to add to every script and 
# every event...
#
# here is nothing you need to change...
# only if you want to add more keys...
# add them in separate block below the last block 
# so you wont get confused... ^-^ 
# for the mouse is now only 5 buttons... 
# if you want more buttons couse your mouse have more...
# then you'll have to wait till microsoft update there stuff... ^-^
#
# i'll try to make the mouse-wheel work...
# i cant promess anything... ^-^
#
# till next update you cann add more stuff or just use it as it is atm...
#
# in the next release will be hopefully the mouse-wheel (not sure though)
# and the joy-stick/pad buttons... 
# but before that i'll have to reasearch a little about that... ^-^
#==============================================================================
module Keyboard

 GetKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
 GetKeyboardState = Win32API.new("user32","GetKeyState",['i'],'i')
 GetSetKeyState = Win32API.new("user32","SetKeyboardState",['i'],'i')

 module_function

 def keyboard(rkey)
GetKeyState.call(rkey) & 0x01 == 1  #
 end

 def key(rkey, key = 0)
GetKeyboardState.call(rkey) & 0x01 == key #
 end
 USED_KEYS = [
 Keys::A,
 Keys::B,
 Keys::C,
 Keys::D,
 Keys::E,
 Keys::F,
 Keys::G,
 Keys::H,
 Keys::I,
 Keys::J,
 Keys::K,
 Keys::L,
 Keys::M,
 Keys::N,
 Keys::O,
 Keys::P,
 Keys::Q,
 Keys::R,
 Keys::S,
 Keys::T,
 Keys::U,
 Keys::V,
 Keys::W,
 Keys::X,
 Keys::Y,
 Keys::Z,
 Keys::SPACE,
 Keys::NUM_DIVIDE,
 Keys::SEMI_COLON,
 Keys::EQUAL,
 Keys::COMMA,
 Keys::DASH,
 Keys::SLASH,
 Keys::ACCENT,
 Keys::OPEN_BRACKET,
 Keys::F_SLASH,
 Keys::CLOSE_BRACKET,
 Keys::PERIOD,
 Keys::N_0,
 Keys::N_1,
 Keys::N_2,
 Keys::N_3,
 Keys::N_4,
 Keys::N_5,
 Keys::N_6,
 Keys::N_7,
 Keys::N_8,
 Keys::N_9,
 Keys::NUM_0,
 Keys::NUM_1,
 Keys::NUM_2,
 Keys::NUM_3,
 Keys::NUM_4,
 Keys::NUM_5,
 Keys::NUM_6,
 Keys::NUM_7,
 Keys::NUM_8,
 Keys::NUM_9,
 Keys::RETURN,
 Keys::SHIFT,
 Keys::ESCAPE,
 Keys::QUOTE
 ]


 module_function

 def check(key)
 Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1  # key 0
 end

 def trigger(key)
return @used_i.include?(key)
 end

 def pressed(key)
return true unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
return false
 end

 def update
@used_i = []
for i in USED_KEYS
  x = check(i)
  if x == true
	@used_i.push(i)
  end
end
 end

end

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...