Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Japanese IME by me
- Disclaimer: I don't know that much Japanese, so if there are any errors please tell me. Also, I wouldn't want to do the Kanji because of the horrifying mess that are known as readings. I mean, I am used to really scary kanji (I use stuff like 嘅, 啲 on a very regular basis) but the readings just kill me since in my language there is usually one reading per character.
- Also, I kind of need to relearn my lua since I am used to using 5.1 not 5.2.
- This is mostly a proof of concept on how IMEs can be done. this is still a one-to-one mapping, but multiple mappings is probably out of my abilities.
- Usage guide:
- In default, Japanese mode is enabled. If you want to switch to English mode, simply press tab.
- Just type the Japanese you want. However, id you want to type katakana, you need to add q in front. In order to type a smaller character, please type l in front. so yes, qltsu will produce ッ. Kya, kyu, kyo and all these two character combos will not work yet (although that is in theory addable), and neither does any kanji. Also, please keep in mind that in order to type ー you should type xx.
- Please note that if you don't press space after each kana, it will not work. For example, if you want to type にほんごでタイプしましょう, you would have to type "ni ho nn go de qta qi qpu shi ma shi lyo u". If you blend them together (like "nihonngo de taipu shi masho"), they will not work since my IME is too dumb.
- Also, please note that deleting fullwidth characters do not exactly work right now. If you want to do so, please move the cursor one square so that it disappears but you know it's in the second half of the kana.
- ]]--
- -- Required APIs
- local event = require("event")
- local table = require("table")
- local term = require("term")
- local keyboard = require("keyboard")
- local unicode = require("unicode")
- local japanese = true
- -- The Unicodes for our characters
- local unitable={ la=0x3041, a=0x3042,
- li=0x3043, i=0x3044,
- lu=0x3045, u=0x3046,
- le=0x3047, e=0x3048,
- lo=0x3049, o=0x304A,
- ka=0x304B, ga=0x304C,
- ki=0x304D, gi=0x304E,
- ku=0x304F, gu=0x3050,
- ke=0x3051, ge=0x3052,
- ko=0x3053, go=0x3054,
- sa=0x3055, za=0x3056,
- si=0x3057, shi=0x3057, zi=0x3058, ji=0x3058,
- su=0x3059, zu=0x305A,
- se=0x305B, ze=0x305C,
- so=0x305D, zo=0x305E,
- ta=0x305F, da=0x3060,
- ti=0x3061, chi=0x3061, di=0x3062, dzi=0x3062,
- ltu=0x3063, tu=0x3064, ltsu=0x3063, tsu=0x3064, du=0x3065, dzu=0x3065,
- te=0x3066, de=0x3067,
- to=0x3068, xdo=0x3069,
- na=0x306A,
- ni=0x306B,
- nu=0x306C,
- ne=0x306D,
- no=0x306E,
- ha=0x306F, ba=0x3070, pa=0x3071,
- hi=0x3072, bi=0x3073, pi=0x3074,
- hu=0x3075, fu=0x3075, bu=0x3076, pu=0x3077,
- he=0x3078, be=0x3079, pe=0x307A,
- ho=0x307B, bo=0x307C, po=0x307D,
- ma=0x307E,
- mi=0x307F,
- mu=0x3080,
- me=0x3081,
- mo=0x3082,
- lya=0x3083, ya=0x3084,
- lyu=0x3085, yu=0x3086,
- lyo=0x3087, yo=0x3088,
- ra=0x3089,
- ri=0x308A,
- ru=0x308B,
- re=0x308C,
- ro=0x308D,
- lwa=0x308E,
- wa=0x308F,
- wi=0x3090,
- we=0x3091,
- wo=0x3092,
- nn=0x3093,
- vu=0x3094,
- lka=0x3095,
- lke=0x3096,
- qla=0x30A1, qa=0x30A2,
- qli=0x30A3, qi=0x30A4,
- qlu=0x30A5, qu=0x30A6,
- qle=0x30A7, qe=0x30A8,
- qlo=0x30A9, qo=0x30AA,
- qka=0x30AB, qga=0x30AC,
- qki=0x30AD, qgi=0x30AE,
- qku=0x30AF, qgu=0x30B0,
- qke=0x30B1, qge=0x30B2,
- qko=0x30B3, qgo=0x30B4,
- qsa=0x30B5, qza=0x30B6,
- qsi=0x30B7, qshi=0x30B7, qzi=0x30B8, qji=0x30B8,
- qsu=0x30B9, qzu=0x30BA,
- qse=0x30BB, qze=0x30BC,
- qso=0x30BD, qzo=0x30BE,
- qta=0x30BF, qda=0x30C0,
- qti=0x30C1, qchi=0x30C1, qdi=0x30C2, qdzi=0x30C2,
- qltu=0x30C3, qtu=0x30C4, qltsu=0x30C3, qtsu=0x30C4, qdu=0x30C5, qdzu=0x30C5,
- qte=0x30C6, qde=0x30C7,
- qto=0x30C8, qdo=0x30C9,
- qna=0x30CA,
- qni=0x30CB,
- qnu=0x30CC,
- qne=0x30CD,
- qno=0x30CE,
- qha=0x30CF, qba=0x30D0, qpa=0x30D1,
- qhi=0x30D2, qbi=0x30D3, qpi=0x30D4,
- qhu=0x30D5, qfu=0x30D5, qbu=0x30D6, qpu=0x30D7,
- qhe=0x30D8, qbe=0x30D9, qpe=0x30DA,
- qho=0x30DB, qbo=0x30DC, qpo=0x30DD,
- qma=0x30DE,
- qmi=0x30DF,
- qmu=0x30E0,
- qme=0x30E1,
- qmo=0x30E2,
- qlya=0x30E3, qya=0x30E4,
- qlyu=0x30E5, qyu=0x30E6,
- qlyo=0x30E7, qyo=0x30E8,
- qra=0x30E9,
- qri=0x30EA,
- qru=0x30EB,
- qre=0x30EC,
- qro=0x30ED,
- qlwa=0x30EE,
- qwa=0x30EF,
- qwi=0x30F0,
- qwe=0x30F1,
- qwo=0x30F2,
- qnn=0x30F3,
- qvu=0x30F4,
- qlka=0x30F5,
- qlke=0x30F6,
- xx=0x30FC
- }
- -- Defines temporary keystrokes
- temporarykeystrokes=""
- function handleoutput()
- if temporarykeystrokes == "do" then
- temporarykeystrokes = "xdo"
- -- debug print("do changed to xdo")
- end
- for k,l in pairs(unitable) do
- if temporarykeystrokes == k then
- term.write(unicode.char(l))
- temporarykeystrokes=""
- return true
- end
- end
- temporarykeystrokes=""
- end
- -- puts event listener
- keydowntrigger = function (keyboardAddress, character, charcode, playerName)
- -- debug print("key down")
- if charcode == 203 then
- local x, y = term.getCursor()
- term.setCursor(x-1, y)
- end
- if charcode == 205 then
- local x, y = term.getCursor()
- term.setCursor(x+1, y)
- end
- if charcode == 14 then
- local x, y = term.getCursor()
- term.setCursor(x-1, y)
- term.write(" ")
- term.setCursor (x-1, y)
- return true
- end
- if charcode == 28 then
- term.write("\n")
- return true
- end
- if charcode == 15 then
- if japanese then
- japanese = false
- return true
- else
- japanese = true
- return true
- end
- end
- if charcode == 1 or charcode == 58 or charcode == 29 or charcode == 42 or charcode == 54 or charcode == 56 or (charcode > 58 and charcode < 71) or (charcode > 88 and charcode < 144) or (charcode > 148) then
- return false
- end
- if charcode == 57 and japanese then
- -- debug print("handle output")
- handleoutput()
- elseif (not japanese) or ((character > 31 and character < 65) or (character > 122 and character > 126)) then
- -- debug print("write char "..charcode.." "..character)
- term.write(unicode.char(character))
- else
- -- debug print("append keystrokes")
- temporarykeystrokes = temporarykeystrokes .. unicode.char(character)
- -- debug print(temporarykeystrokes)
- end
- end
- while true do
- local event,kbadr,ch,co,pn = term.pull("key_down")
- keydowntrigger(kbadr,ch,co,pn)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement