Works for me (I use a QWERTY Keyboard).
#-------------------------------------------------------------------------------
# Script original: Cybersam
# Añadidas teclas en español: houndninja@gmail.com
# Readaptado por NEWOLD
#-------------------------------------------------------------------------------
module Keyb
$keys = {}
$keys["MouseL"] = 0x01 # Botón Izquierdo
$keys["MouseR"] = 0x02 # Botón Derecho
$keys["MouseM"] = 0x04 # Botón medio
$keys["Mouse4"] = 0x05 # Cuarto Botón
$keys["Mouse5"] = 0x06 # Quinto Botón
# Teclas de Controles
$keys["Back"] = 0x08 # Tecla Retroceder/Borrar
$keys["Tab"] = 0x09 # Tecla Tab
$keys["Enter"] = 0x0D # Tecla Enter
$keys["Shift"] = 0x10 # Tecla Shift
$keys["Ctrl"] = 0x11 # Tecla Control
$keys["Alt"] = 0x12 # Tecla Alt
$keys["Pause"] = 0x13 # Tecla de Pausa
$keys["Caps"] = 0x14 # Tecla Bloq Mayus
$keys["Esc"] = 0x1B # Tecla Escape (ESC)
$keys["Space"] = 0x20 # Tecla Espaciadora
$keys["AvPag"] = 0x21 # Tecla Siguiente
$keys["RePag"] = 0x22 # Tecla Anterior
$keys["End"] = 0x23 # Tecla Fin
$keys["Home"] = 0x24 # Tecla Inicio
# Teclas de Direcciones
$keys["Left"] = 0x25 # Tecla Flecha Izquierda
$keys["Up"] = 0x26 # Tecla Flecha Arriba
$keys["Right"] = 0x27 # Tecla Flecha Derecha
$keys["Down"] = 0x28 # Tecla Flecha Abajo
$keys["Select"] = 0x29
# Otras teclas
$keys["Print"] = 0x2A # Tecla Imprimir
$keys["Snapshot"] = 0x2C # Tecla Capturar Pantalla
$keys["Ins"] = 0x2D # Tecla Insert
$keys["Del"] = 0x2E # Tecla Suprimir
# Teclas Numéricas Superiores
$keys["0"] = 0x30
$keys["1"] = 0x31
$keys["2"] = 0x32
$keys["3"] = 0x33
$keys["4"] = 0x34
$keys["5"] = 0x35
$keys["6"] = 0x36
$keys["7"] = 0x37
$keys["8"] = 0x38
$keys["9"] = 0x39
# Teclas de Windows
$keys["Lwin"] = 0x5B # Tecla Windows Izquierda
$keys["Rwin"] = 0x5C # Tecla Windows Derecha
$keys["Apps"] = 0x5D # Tecla Aplicaciones
# Teclas del Pad Numérico
$keys["Pad0"] = 0x60
$keys["Pad1"] = 0x61
$keys["Pad2"] = 0x62
$keys["Pad3"] = 0x63
$keys["Pad4"] = 0x64
$keys["Pad5"] = 0x65
$keys["Pad6"] = 0x66
$keys["Pad7"] = 0x67
$keys["Pad8"] = 0x68
$keys["Pad9"] = 0x69
$keys["Multiply"] = 0x6A # Tecla Multiplicar
$keys["Add"] = 0x6B # Tecla Sumar
$keys["Separator"] = 0x6C
$keys["Substract"] = 0x6D # Tecla Restar
$keys["Decimal"] = 0x6E
$keys["Divide"] = 0x6F # Tecla Dividir
# Teclas de Funciones
$keys["F1"] = 0x70
$keys["F2"] = 0x71
$keys["F3"] = 0x72
$keys["F4"] = 0x73
$keys["F5"] = 0x74
$keys["F6"] = 0x75
$keys["F7"] = 0x76
$keys["F8"] = 0x77
$keys["F9"] = 0x78
$keys["F10"] = 0x79
$keys["F11"] = 0x7A
$keys["F12"] = 0x7B
$keys["Numlock"] = 0x90
$keys["Scroll"] = 0x91 # Tecla Bloq Despl
# Teclas de cada letra
$keys["A"] = 0x41
$keys["B"] = 0x42
$keys["C"] = 0x43
$keys["D"] = 0x44
$keys["E"] = 0x45
$keys["F"] = 0x46
$keys["G"] = 0x47
$keys["H"] = 0x48
$keys["I"] = 0x49
$keys["J"] = 0x4A
$keys["K"] = 0x4B
$keys["L"] = 0x4C
$keys["M"] = 0x4D
$keys["N"] = 0x4E
$keys["O"] = 0x4F
$keys["P"] = 0x50
$keys["Q"] = 0x51
$keys["R"] = 0x52
$keys["S"] = 0x53
$keys["T"] = 0x54
$keys["U"] = 0x55
$keys["V"] = 0x56
$keys["W"] = 0x57
$keys["X"] = 0x58
$keys["Y"] = 0x59
$keys["Z"] = 0x5A
# Teclas de Signos de Puntuación
$keys["Sep"] = 0xBC # Tecla Coma , ;
$keys["Dash"] = 0xBD # Tecla Guión - _
$keys["Dott"] = 0xBE # Tecla Punto . :
# Teclas de carácteres especiales
$keys["Ç"] = 0xBF # ç Ç }
$keys["Ñ"] = 0xc0# ñ Ñ
$keys["Ac1"] = 0xde # Acento y Diéresis ´¨
$keys["Ac2"] = 0xBA # Acento al revés `^
$keys["Plus"] = 0xBB # + * ]
$keys["Prg2"] = 0xdb # ' ?
$keys["Ord"] = 0xdc # º ª \
$keys["Prg1"] = 0xdd # ¡ ¿
$keys["Cmp"] = 0xe2 # Comparación < >
# Teclas de Control Específicas
$keys["Lshift"] = 0xA0 # Shift izquierdo
$keys["Rshift"] = 0xA1 # Shift derecho
$keys["Lctrl"] = 0xA2 # Ctrl izquierdo
$keys["Rctrl"] = 0xA3 # Ctrl derecho
$keys["Lalt"] = 0xA4 # Alt izquierdo
$keys["Ralt"] = 0xA5 # Alt derecho
#--------------------------------------------------------------------------
# Nombres de cada tecla
#--------------------------------------------------------------------------
Names = {
0x20 => [" "," "," "],
0xdc => ["º","ª","\\"], 0x31 => ["1","!","|"], 0x32 => ["2",'"',"@"],
0x33 => ["3","·","#"], 0x34 => ["4","$","~"], 0x35 => ["5","%","€"],
0x36 => ["6","&","¬"], 0x37 => ["7","/",nil], 0x38 => ["8","(",nil],
0x39 => ["9",")",nil], 0x30 => ["0","=",nil], 0xdb => ["'","?",nil],
0xdd => ["¡","¿",nil], 0x41 => ["a","A",nil], 0x42 => ["b","B",nil],
0x43 => ["c","C",nil], 0x44 => ["d","D",nil], 0x45 => ["e","E","€"],
0x46 => ["f","F",nil], 0x47 => ["g","G",nil], 0x48 => ["h","H",nil],
0x49 => ["i","I",nil], 0x4A => ["j","J",nil], 0x4B => ["k","K",nil],
0x4C => ["l","L",nil], 0x4D => ["m","M",nil], 0x4E => ["n","N",nil],
0xc0 => ["ñ","Ñ",nil], 0x4F => ["o","O",nil], 0x50 => ["p","P",nil],
0x51 => ["q","Q",nil], 0x52 => ["r","R",nil], 0x53 => ["s","S",nil],
0x54 => ["t","T",nil], 0x55 => ["u","U",nil], 0x56 => ["v","V",nil],
0x57 => ["w","W",nil], 0x58 => ["x","X",nil], 0x59 => ["y","Y",nil],
0x5A => ["z","Z",nil], 0xe2 => ["<",">",nil], 0xBA => ["`","^","["],
0xBB => ["+","*","]"], 0xde => ["´","¨","{"], 0xBF => ["ç","Ç","}"],
0xBC => [",",";",nil], 0xBE => [".",":",nil], 0xBD => ["-","_",nil],
0x6F => ["/","/","/"], 0x6A => ["*","*","*"], 0x6D => ["-","-","-"],
0x6B => ["+","+","+"], 0x6E => [".",".","."], 0x60 => ["0","0","0"],
0x61 => ["1","1","1"], 0x62 => ["2","2","2"], 0x63 => ["3","3","3"],
0x64 => ["4","4","4"], 0x65 => ["5","5","5"], 0x66 => ["6","6","6"],
0x67 => ["7","7","7"], 0x68 => ["8","8","8"], 0x69 => ["9","9","9"],
"Special" => [
[["á","Á"],["é","É"],["í","Í"],["ó","Ó"],["ú","Ú"]],
[["ä","Ä"],["ë","Ë"],["ï","Ï"],["ö","Ö"],["ü","Ü"]],
[["à","À"],["è","È"],["ì","Ì"],["ò","Ò"],["ù","Ù"]],
[["â","Â"],["ê","Ê"],["î","Î"],["ô","Ô"],["û","Û"]]
]
}
#--------------------------------------------------------------------------
# Variable especial para guardar los acentos y diéresis
#--------------------------------------------------------------------------
@store_key = nil
#--------------------------------------------------------------------------
# Creamos las variables de llamada Win32api
#--------------------------------------------------------------------------
GetKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
GetKeyboardState = Win32API.new("user32","GetKeyState",['i'],'i')
#--------------------------------------------------------------------------
# Otras Variables
#--------------------------------------------------------------------------
KeyRepeatCounter = {}
# Letras a las que les afecta el caps lock
@caps_letters = [0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,
0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,
0x57,0x58,0x59,0x5A,0xc0,0xBF]
#--------------------------------------------------------------------------
# Métodos del módulo
#--------------------------------------------------------------------------
def Keyb.update
for key in KeyRepeatCounter.keys
if KeyRepeatCounter[key] != nil
if GetKeyState.call(key) != 0
KeyRepeatCounter[key] += 1
KeyRepeatCounter[key] = 1 if KeyRepeatCounter[key] > 1000
else
KeyRepeatCounter[key] = nil
end
elsif KeyRepeatCounter[key] != nil
KeyRepeatCounter[key] = nil
end
end
end
#--------------------------------------------------------------------------
def Keyb.press?(key)
return false if key == nil
return true unless KeyRepeatCounter[key].nil?
return key_pressed?(key)
end
#--------------------------------------------------------------------------
def Keyb.trigger?(key)
return false if key == nil
return false if GetKeyState.call(key) == 0
KeyRepeatCounter[key] = 0 if KeyRepeatCounter[key].nil?
return (KeyRepeatCounter[key] == 0)
end
#--------------------------------------------------------------------------
def Keyb.trigger2?(key)
return Keyb.trigger?(key)
end
#--------------------------------------------------------------------------
def Keyb.repeat?(key)
return false if key == nil
count = KeyRepeatCounter[key]
return true if count == 0
if count.nil?
return key_pressed?(key)
else
return (count >= 23 and (count - 23) % 6 == 0)
end
end
#--------------------------------------------------------------------------
def Keyb.repeat_fast?(key)
return false if key == nil
count = KeyRepeatCounter[key]
return true if count == 0
if count.nil?
return key_pressed?(key)
else
return (count >= 7 and (count - 7) % 3 == 0)
end
end
#--------------------------------------------------------------------------
def Keyb.key_pressed?(key)
if (GetKeyState.call(key).abs & 0x8000 == 0x8000)
KeyRepeatCounter[key] = 0
return true
end
return false
end
#--------------------------------------------------------------------------
def Keyb.block(key) # Condición de teclas bloqueadas
GetKeyboardState.call(key) == 1
end
#--------------------------------------------------------------------------
def Keyb.getKey(key)
if Keyb.caps_effects.include?(key)
if Keyb.block($keys["Caps"])
index = Keyb.press?($keys["Shift"]) ? 0 : 1
elsif Keyb.press?($keys["Shift"])
index = 1
elsif Keyb.press?($keys["Ralt"])
index = 2
else
index = 0
end
else
if Keyb.press?($keys["Shift"])
index = 1
elsif Keyb.press?($keys["Ralt"])
index = 2
else
index = 0
end
end
name = (Names[key] != nil) ? Names[key][index] : nil
return nil if name.nil?
if (key == 0xde or key == 0xBA) and Keyb.store_key == nil and index != 2
Keyb.store_key = Names[key][index]; return nil
elsif Keyb.store_key != nil
dec = Keyb.store_key
Keyb.store_key = nil
case dec
when "`": pos = 0
when "¨": pos = 1
when "`": pos = 2
when "^": pos = 3
else
pos = 0
end
case name
when "a": return Names["Special"][pos][0][0]
when "e": return Names["Special"][pos][1][0]
when "i": return Names["Special"][pos][2][0]
when "o": return Names["Special"][pos][3][0]
when "u": return Names["Special"][pos][4][0]
when "A": return Names["Special"][pos][0][1]
when "E": return Names["Special"][pos][1][1]
when "I": return Names["Special"][pos][2][1]
when "O": return Names["Special"][pos][3][1]
when "U": return Names["Special"][pos][4][1]
else
return dec + name
end
else
return name
end
end
#--------------------------------------------------------------------------
def Keyb.store_key=(val)
@store_key = val
end
#--------------------------------------------------------------------------
def Keyb.store_key
return @store_key
end
#--------------------------------------------------------------------------
def Keyb.caps_effects
return @caps_letters
end
#--------------------------------------------------------------------------
def Keyb.count(key)
return (KeyRepeatCounter[key].nil?) ? 0 : KeyRepeatCounter[key]
end
#--------------------------------------------------------------------------
def Keyb.clear
KeyRepeatCounter.clear
end
#--------------------------------------------------------------------------
def Keyb.clear_left_click
KeyRepeatCounter.delete(0x01)
end
#--------------------------------------------------------------------------
end