Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard
#1
Keyboard
by corbaque
Jun 11 2007

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Hello.

This script is really inutuitive, and optimised.

Script :
Code:
#===================================
# Keybord
#---------------------------------------------------------------
# By Corbaque - 17/05/07 - http://rpgmxp.ch
#---------------------------------------------------------------
# Thanks to Cybersam for gived name of DLL
#---------------------------------------------------------------
# If you want to use trigger, think to update :
### Keys.update
#---------------------------------------------------------------
# Press condition :
### if press("a")
# Repeat condition :
### if repeat("a")
# Trigger condition :
### if trigger("a")
#---------------------------------------------------------------
# Key list line 46 at line 135
#===================================
Press = Win32API.new("user32","GetKeyState",['i'],'i')
#---------------------------------------------------------------
# Click
#---------------------------------------------------------------
def trigger(n)
  R[n][1]
end
#---------------------------------------------------------------
# Press
#---------------------------------------------------------------
def press(n)
  (Press.call(TAB_KEY[n]) != 0 and Press.call(TAB_KEY[n]) != 1)
end
#---------------------------------------------------------------
# Repeat
#---------------------------------------------------------------
def repeat(n)
  if Graphics.frame_count % 3 == 0
    return (Press.call(TAB_KEY[n]) != 0 and Press.call(TAB_KEY[n]) != 1)
  else
    return false
  end
end
#---------------------------------------------------------------
# Key list
#---------------------------------------------------------------
TAB_KEY = {
"click left" => 1,
"ml" => 1,
"click right" => 2,
"mr" => 2,
"click middle" => 4,
"mm" => 4,
"del" => 8,
"tab" => 9,
"enter" => 13,
"shift" => 16,
"pause" => 19,
"maj lock" => 20,
"esc" => 27,
"space" => 32,
"pg up" => 33,
"pg down" => 34,
"end" => 35,
"home" => 36,
"left" => 37,
"up" => 38,
"right" => 39,
"down" => 40,
"select" => 41,
"print" => 42,
"impr" => 43,
"insert" => 44,
"suppr" => 46,
"q" => 65,
"b" => 66,
"c" => 67,
"d" => 68,
"e" => 69,
"f" => 70,
"g" => 71,
"h" => 72,
"i" => 73,
"j" => 74,
"k" => 75,
"l" => 76,
";" => 77,
"n" => 78,
"o" => 79,
"p" => 80,
"a" => 81,
"r" => 82,
"s" => 83,
"t" => 84,
"u" => 85,
"v" => 86,
"z" => 87,
"x" => 88,
"y" => 89,
"w" => 90,
"0" => 96,
"1" => 97,
"2" => 98,
"3" => 99,
"4" => 100,
"5" => 101,
"6" => 102,
"7" => 103,
"8" => 104,
"9" => 105,
"*" => 106,
"+" => 107,
"num" => 108,
"-" => 109,
"." => 110,
"/" => 111,
"F1" => 112,
"F2" => 113,
"F3" => 114,
"F4" => 115,
"F5" => 116,
"F6" => 117,
"F7" => 118,
"F8" => 119,
"F9" => 120,
"F10" => 121,
"F11" => 122,
"F12" => 123,
"lmaj" => 160,
"rmaj" => 161,
"ctrl" => 162,
"lctrl" => 162,
"rctrl" => 163,
"lalt" => 164,
"ralt" => 165,
"m" => 188
}
R = TAB_KEY.clone
R.keys.each do |k|
  R[k] = [false, false, false]
end
#---------------------------------------------------------------
# Update
#---------------------------------------------------------------
module Keys
  module_function
  def update
    TAB_KEY.keys.each do |n|
      m = R[n][0]
      pr = (Press.call(TAB_KEY[n]) != 0 and Press.call(TAB_KEY[n]) != 1)
      tr = pr == true and m == false
      R[n] = [pr, tr, m]
    end
  end
end

To use.
Key "a" is pressed ?
if press("a")
Key "enter" is repeated ?
if repeat("enter")
Key "esc" is triggered ?
if trigger("esc")

Intuitive, no ?

If you want to use trigger method, you have to add "Keys.update" with "Graphics.update".

Enjoy.
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Keyboard (optimal version) corbaque 0 2,170 08-30-2007, 01:00 PM
Last Post: corbaque
  Complete Keyboard Input Script Dubealex 0 2,419 03-09-2005, 01:00 PM
Last Post: Dubealex



Users browsing this thread: