User script callback for specific characters : function
query
Syntax
Description
keyboard.alt()
Returns state of ALT key : boolean
keyboard.ctrl()
Returns state of CTRL key : boolean
keyboard.meta()
Returns state of META key : boolean
keyboard.shift()
Returns state of SHIFT key : boolean
keyboard.state[string]
Returns state of defined key, eg. [‘A’] : boolean
example
MU=require("musicutil")engine.name="PolySub"my_string=""functioninit()engine.ampAtk(0)engine.ampDec(0.1)engine.ampSus(0.05)engine.ampRel(0.5)endfunctionkeyboard.char(character)my_string=my_string..character-- add characters to my stringredraw()endfunctionkeyboard.code(code,value)ifvalue==1orvalue==2then-- 1 is down, 2 is held, 0 is releaseifcode=="BACKSPACE"thenmy_string=my_string:sub(1,-2)-- erase characters from my_stringelseifcode=="ENTER"thenmy_string=""-- clear my_stringnote_on()-- play a bellendredraw()endendfunctionredraw()screen.clear()screen.move(10,30)screen.text(my_string)screen.update()endfunctionnote_on()fori=1,4doengine.start(i,2500+(250*i/150))endclock.run(note_off)endfunctionnote_off()clock.sleep(0.1)fori=1,4doengine.stop(i)endend
description
Deciphers keyboard (typing, not piano) input and executes user-assignable callbacks based on key codes, character case, and held state. Specific functions are available to query modifier states: shift, alt, ctrl, and meta. Three key state values are reported as part of the code callback: 1 for initial press, 2 for hold, 0 for release.