Script Acentos

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

#############################################

# Acentos desde teclado #


# Compatible : Essentials 16.2 #
# Autor : Bezier #
#############################################
# Jódete, Maruno, que tengo acentos #
#############################################

class Window_TextEntry_Keyboard < Window_TextEntry

# Acentos básicos [ ´ , ` , ¨ , ^ ]
@@Acentos = [180, 96, 168, 94]
@@AcentosConversion=[
['A','E','I','O','U','a','e','i','o','u'],
['Á','É','Í','Ó','Ú','á','é','í','ó','ú'],
['À','È','Ì','Ò','Ù','à','è','ì','ò','ù'],
['Ä','Ë','Ï','Ö','Ü','ä','ë','ï','ö','ü'],
['Â','Ê','Î','Ô','Û','â','ê','î','ô','û']
]

def update
@frame+=1
@frame%=20
self.refresh if ((@frame%10)==0)
return if !self.active
# Moving cursor
if Input.repeat?(Input::LEFT)
if @helper.cursor > 0
@helper.cursor-=1
@frame=0
self.refresh
end
return
end
if Input.repeat?(Input::RIGHT)
if @helper.cursor < self.text.scan(/./m).length
@helper.cursor+=1
@frame=0
self.refresh
end
return
end
# Backspace
if Input.repeatex?(8) || Input.repeatex?(0x2E)
self.delete if @helper.cursor > 0
return
end
if !@toUnicode
@toUnicode=Win32API.new("user32.dll","ToUnicode","iippii","i") rescue nil
@mapVirtualKey=Win32API.new("user32.dll","MapVirtualKey","ii","i") rescue nil
@getKeyboardState=Win32API.new("user32.dll","GetKeyboardState","p","i")
rescue nil
end

@alt_gr = false

if @getKeyboardState
@acento = 0 if !@acento
kbs="\0"*256
@getKeyboardState.call(kbs)
kbcount=0
for i in 3...256
if Input.triggerex?(i)

if i==17 # Alt Gr Key


@alt_gr=true
end

vsc=@mapVirtualKey.call(i,0)
buf="\0"*8
ret=@toUnicode.call(i,vsc,kbs,buf,4,0)
if ret>0
b=buf.unpack("v*")

if @@Acentos.include?(b[0])
@acento = @@Acentos.index(b[0]) + 1
return
elsif @@AcentosConversion[0].include?(buf[0].chr) && @acento > 0
idx = @@AcentosConversion[0].index(buf[0].chr)
insert(@@AcentosConversion[@acento][idx])
@acento = 0
return
else
@acento=0
end

for j in 0...ret
if buf[j]<=0x7F
insert(buf[j].chr)
elsif buf[j]<=0x7FF
insert((0xC0|((buf[j]>>6)&0x1F)).chr+(0x80|(buf[j]&0x3F)).chr)
else
str=(0xE0|((buf[j]>>12)&0x0F)).chr
str+=(0x80|((buf[j]>>6)&0x3F)).chr
str+=(0x80|(buf[j]&0x3F)).chr
insert(str)
end
kbcount+=1
end
end
end
end
return if kbcount>0
end
# Letter keys
for i in 65..90
if Input.repeatex?(i)
shift=(Input.press?(Input::SHIFT)) ? 0x41 : 0x61
insert((shift+(i-65)).chr)
return
end
end
# Number keys
shifted="=!\"·$%&/()"
unshifted="0123456789"
for i in 48..57
if Input.repeatex?(i)
insert((Input.press?(Input::SHIFT)) ? shifted[i-48].chr : unshifted[i-
48].chr)
return
end
end
end
end

You might also like