Main Menu
  • Welcome to The RPG Maker Resource Kit.

Delete Account Please

Started by Kipe, July 09, 2008, 12:18:39 AM

0 Members and 1 Guest are viewing this topic.

Kipe

.

modern algebra


ahref

i have it:

#==============================================================================
# Keyboard Input Module
#----------------------------------------------------------------------------
# Script by Cybersam
#==============================================================================

module Input
  @keys = []
  @pressed = []
  Mouse_Left = 1
  Mouse_Right = 2
  Mouse_Middle = 4
  Back= 8
  Tab = 9
  Enter = 13
  Shift = 16
  Ctrl = 17
  Alt = 18
  Esc = 27
  Space = 32
  Numberkeys = {}
  Numberkeys[0] = 48        # => 0
  Numberkeys[1] = 49        # => 1
  Numberkeys[2] = 50        # => 2
  Numberkeys[3] = 51        # => 3
  Numberkeys[4] = 52        # => 4
  Numberkeys[5] = 53        # => 5
  Numberkeys[6] = 54        # => 6
  Numberkeys[7] = 55        # => 7
  Numberkeys[8] = 56        # => 8
  Numberkeys[9] = 57        # => 9
  Numberpad = {}
  Numberpad[0] = 45
  Numberpad[1] = 35
  Numberpad[2] = 40
  Numberpad[3] = 34
  Numberpad[4] = 37
  Numberpad[5] = 12
  Numberpad[6] = 39
  Numberpad[7] = 36
  Numberpad[8] = 38
  Numberpad[9] = 33
  Letters = {}
  Letters["A"] = 65
  Letters["B"] = 66
  Letters["C"] = 67
  Letters["D"] = 68
  Letters["E"] = 69
  Letters["F"] = 70
  Letters["G"] = 71
  Letters["H"] = 72
  Letters["I"] = 73
  Letters["J"] = 74
  Letters["K"] = 75
  Letters["L"] = 76
  Letters["M"] = 77
  Letters["N"] = 78
  Letters["O"] = 79
  Letters["P"] = 80
  Letters["Q"] = 81
  Letters["R"] = 82
  Letters["S"] = 83
  Letters["T"] = 84
  Letters["U"] = 85
  Letters["V"] = 86
  Letters["W"] = 87
  Letters["X"] = 88
  Letters["Y"] = 89
  Letters["Z"] = 90
  Fkeys = {}
  Fkeys[1] = 112
  Fkeys[2] = 113
  Fkeys[3] = 114
  Fkeys[4] = 115
  Fkeys[5] = 116
  Fkeys[6] = 117
  Fkeys[7] = 118
  Fkeys[8] = 119
  Fkeys[9] = 120
  Fkeys[10] = 121
  Fkeys[11] = 122
  Fkeys[12] = 123
  Collon = 186        # => \ |
  Equal = 187         # => = +
  Comma = 188         # => , <
  Underscore = 189    # => - _
  Dot = 190           # => . >
  Backslash = 191     # => / ?
  Lb = 219
  Rb = 221
  Quote = 222         # => '"
  #-------------------------------------------------------------------------------
  USED_KEYS = [Mouse_Left, Mouse_Right, Mouse_Middle]
  #-------------------------------------------------------------------------------
 
module_function
  #--------------------------------------------------------------------------
  def triggered?(key)
    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1
  end
  #--------------------------------------------------------------------------
  def check(key)
    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1
  end
  #--------------------------------------------------------------------------
  def pressed?(key)
    return true unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
    return false
  end
  #--------------------------------------------------------------------------
  def mouse_update
    @used_i = []
    for i in USED_KEYS
      x = check(i)
      if x == true
        @used_i.push(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def self.C
    self.trigger?(C)
  end
  #--------------------------------------------------------------------------
  def self.B
    self.trigger?(B)
  end
  #--------------------------------------------------------------------------
  def self.A
    self.trigger?(A)
  end
  #--------------------------------------------------------------------------
  def self.Down
    self.trigger?(DOWN)
  end
  #--------------------------------------------------------------------------
  def self.Up
    self.trigger?(UP)
  end
  #--------------------------------------------------------------------------
  def self.Right
    self.trigger?(RIGHT)
  end
  #--------------------------------------------------------------------------
  def self.Left
    self.trigger?(LEFT)
  end
  #--------------------------------------------------------------------------
  def self.Anykey
    if A or B or C or Down or Up or Right or Left
      return true
    else
      return false
    end
  end
  #--------------------------------------------------------------------------
end


thats the script

to utilize it use an if statement eg.
if Input.triggered?(32) # [SPACE]
would be for pressing space

line 8-21 gives you more of the key codes :D

modern algebra

Yeah, if you are using it for an event as well, then all you'd need to do is go to Conditional Branch: Script: Input.triggered? (Input:Space)

ahref

QuoteHow to use it:

You must do IF statements in your scripts in order for this to work... so we'll look at how to add an actions to the button E that would print the message YIPEE on screen.

STEP 1:
The class where you want to use the condition must be a child class of Keyboard_Input ... You do this like that, example: You will put the code in Scene_Map:
CODE

class Scene_Map < Keyboard_Input


this is the first line (beside the comments), now, what was in Keyboard_Input is accesible from Scene_Map.

STEP 2:

TO do an IF, you can check my RGSS Reference for further help. CLICK HERE. But it would look like that:

CODE
if keyboard(R_Key_E)
       print "YIPEE!"
end


-> That IF must be in the UPDATE method, that way it's always being checked out.

The syntax used: keyboard(R_Key_E)

R_Key_E This is where you write the key you want to bind to the action in the IF. The complete list is in Keyboard_Input class.

this is how to use the above script. id recomend using the one i posted though as it seems newer and has a few more features

modern algebra

I haven't looked at this script much - it's weird anyway - it doesn't seem like there is much there.

Anyway, why aren't you using the one you posted before? For that one, it looks like all you need to do is:


Input.triggered? (Input::Letters["W"])


And if it's in a conditional branch don't put "if". Only put the if when you are using RGSS.

FOr the one you have, idk. I'd need to play around with it. My first guess would be this:

Input_keyboard.keyboard (Input_keyboard::R_Key_W)