Keyboard Input Module
#1
Keyboard Input Module
by Near_Fantastica
Jul 12 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.


Features :

I know there is a few keyboard input scripts out there but not like this one... this one works fundamentally different then the others you press and key and it returns what was pressed... which lets you easily have string input for names, conversations, or what ever you see fit…

Syntax:

Code:
if Input.get_function == "function"
if Input.get_letters== "letter"
if Input.get_numbers == "number"
if Input.get_key == "char"
if Input.get_direction== "number" # Number Pad




Script :

Code:
#======================================
# â–�  Keyboard Input Module
#======================================
#  By: Near Fantastica
#   Date: 06.07.05
#   Version: 3
#======================================
module Input
#--------------------------------------------------------------------------  
@back = 8
@shift = 16
@ctrl = 17
@alt = 18
@esc = 27
@space = 32
@numberpad = (33..40).to_a + [12,45]
@numbers = (48..57).to_a
@letters = (65..90).to_a
@fkeys = (112..123).to_a
@collon = 186
@equal = 187
@comma = 188
@underscore = 189
@dot = 190
@backslash = 191
@lb = 219
@rb = 221
#--------------------------------------------------------------------------  
def Input.getstate(key)
  return true unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
  return false
end
#--------------------------------------------------------------------------
def Input.get_direction
  for key in @numberpad
    if Input.getstate(key)
      case key
      when 45
        return "0" # Same As Insert
      when 33
        return "9" # Same As Page Up
      when 34
        return "3" # Same As Page Down
      when 35
        return "1" # Same As Page End
      when 36  
        return "7" # Same As Page Home
      when 37
        return "4" # Same As Left
      when 38
        return "8" # Same As Up
      when 39
        return "6" # Same As Right
      when 40
        return "2" # Same As Down
      when 12
        return "5"
      end
    end
  end
end
#--------------------------------------------------------------------------
def Input.get_function
  if Input.getstate(@back)
    return "Back"
  end
  if Input.getstate(@backslash)
    return "/"
  end
  if Input.getstate(@esc)
    return "Esc"
  end
  if Input.getstate(@ctrl)
    return "Ctrl"
  end
  if Input.getstate(@alt)
    return "Alt"
  end
  for key in @fkeys
    if Input.getstate(key)
      num = key - 111
      return "F" + num.to_s
    end
  end
  return nil
end
#--------------------------------------------------------------------------
def Input.get_letters
  for key in @letters
    if Input.getstate(key)
      if Input.getstate(@shift)
        return key.wow.upcase  
      else
        return key.wow.downcase
      end
    end
  end
  return nil
end
#--------------------------------------------------------------------------
def Input.get_numbers
  return nil if Input.getstate(@shift)
  for key in @numbers
    if Input.getstate(key)
      return key.wow
    end
  end
  return nil
end
#--------------------------------------------------------------------------
def Input.get_key
  if Input.getstate(@space)
    return " "
  end
  if Input.getstate(@backslash) and Input.getstate(@shift)
    return "?"
  end
  if Input.getstate(@lb)
    if Input.getstate(@shift)
      return "{"
    else
      return "["
    end
  end
  if Input.getstate(@rb)
    if Input.getstate(@shift)
      return "}"
    else
      return "]"
    end
  end
  if Input.getstate(@comma)
    if Input.getstate(@shift)
      return "<"
    else
      return ","
    end
  end
  if Input.getstate(@dot)
    if Input.getstate(@shift)
      return ">"
    else
      return "."
    end
  end
  if Input.getstate(@collon)
    if Input.getstate(@shift)
      return ":"
    else
      return ";"
    end
  end
  if Input.getstate(@equal)
    if Input.getstate(@shift)
      return "+"
    else
      return "="
    end
  end
  if Input.getstate(@underscore)
    if Input.getstate(@shift)
      return "_"
    else
      return "-"
    end
  end
  for key in @numbers
    if Input.getstate(key) and Input.getstate(@shift)
      case key
      when 48
        return ")"
      when 49
        return "!"
      when 50
        return "@"
      when 51
        return "#"
      when 52
        return "$"
      when 53
        return "%"
      when 54
        return "^"
      when 55
        return "&"
      when 56
        return "*"
      when 57
        return "("
      end
    end
  end
  return nil
end
end


Take Care,
Near
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Ini module Nick 0 2,269 05-21-2006, 01:00 PM
Last Post: Nick



Users browsing this thread: 1 Guest(s)