diff options
| author | Omar Rizwan <omar@omar.website> | 2024-01-30 18:40:15 +0000 |
|---|---|---|
| committer | Omar Rizwan <omar@omar.website> | 2024-01-30 18:40:15 +0000 |
| commit | 7ee527f792c6a6c11fa257d0c66633de13f6a5b3 (patch) | |
| tree | 8516413fb53b7bdba3fd223505e9a6fd659ce964 /virtual-programs | |
| parent | Start on Web UI for identifying & printing connected keyboards (diff) | |
| download | folk-7ee527f792c6a6c11fa257d0c66633de13f6a5b3.tar.gz folk-7ee527f792c6a6c11fa257d0c66633de13f6a5b3.zip | |
web-keyboards: Niceties
Spaces between keypresses. Don't show keypresses from before page
render. Don't double up keypresses (only count keydowns).
Diffstat (limited to 'virtual-programs')
| -rw-r--r-- | virtual-programs/web-keyboards.folk | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/virtual-programs/web-keyboards.folk b/virtual-programs/web-keyboards.folk index a3a4435d..560186e7 100644 --- a/virtual-programs/web-keyboards.folk +++ b/virtual-programs/web-keyboards.folk @@ -9,7 +9,7 @@ When the keyboards are /keyboards/ { [join [lmap kb $keyboards { subst { <dt>$kb</dt> <dd> - <pre id="$kb-presses"></pre><br> + <code id="$kb-presses"></code><br> <button>Print</button> </dd> } }] "\n"] @@ -23,14 +23,16 @@ When the keyboards are /keyboards/ { ws.onopen = () => { document.getElementById('status').innerHTML = "<span style=background-color:seagreen;color:white;>Connnected</span>"; send(` - Assert when keyboard /kb/ claims key /k/ is /t/ with modifiers /m/ timestamp /ts/ {{chan kb k t m ts} { - ::websocket::send \$chan text "\$kb||\$k" + Assert when keyboard /kb/ claims key /k/ is down with modifiers /m/ timestamp /ts/ {{chan kb k m ts} { + if {\$ts > [clock milliseconds]} { + ::websocket::send \$chan text "\$kb||\$k" + } }} with environment \[list \$chan] `); }; ws.onclose = window.onbeforeunload = () => { document.getElementById('status').innerHTML = "<span style=background-color:red;color:white;>Disconnnected</span>"; - send(`Retract when keyboard /kb/ claims key /k/ is /t/ with modifiers /m/ timestamp /ts/ /anything/ with environment \[list \$chan]`) + send(`Retract when keyboard /kb/ claims key /k/ is down with modifiers /m/ timestamp /ts/ /anything/ with environment \[list \$chan]`) setTimeout(() => { wsConnect(); }, 1000); }; ws.onerror = (err) => { @@ -40,7 +42,7 @@ When the keyboards are /keyboards/ { } ws.onmessage = (msg) => { const \[kb, key] = msg.data.split("||"); - document.getElementById(kb + "-presses").innerText += key; + document.getElementById(kb + "-presses").innerText += key + " "; } }; wsConnect(); |
