Here we should all post our fixes for this problem.
My fix has a problem, that keys repeat way too fast, and the only way to stop that is to change the #KeyTypeDelayMs to something so large you have to type the speed of a 2 year old to not miss key presses.
Here it is, see if you can fix it or if you already have a working one just post it:
Code: Select all
Procedure.s GetKeyboardASCII()
kchar.s=""
If ElapsedMilliseconds()-lastKeyTypeMs >= #KeyTypeDelayMs
If KeyboardPushed(#PB_Key_0) Or KeyboardPushed(#PB_Key_Pad0)
kchar="0"
ElseIf KeyboardPushed(#PB_Key_1) Or KeyboardPushed(#PB_Key_Pad1)
kchar="1"
ElseIf KeyboardPushed(#PB_Key_2) Or KeyboardPushed(#PB_Key_Pad2)
kchar="2"
ElseIf KeyboardPushed(#PB_Key_3) Or KeyboardPushed(#PB_Key_Pad3)
kchar="3"
ElseIf KeyboardPushed(#PB_Key_4) Or KeyboardPushed(#PB_Key_Pad4)
kchar="4"
ElseIf KeyboardPushed(#PB_Key_5) Or KeyboardPushed(#PB_Key_Pad5)
kchar="5"
ElseIf KeyboardPushed(#PB_Key_6) Or KeyboardPushed(#PB_Key_Pad6)
kchar="6"
ElseIf KeyboardPushed(#PB_Key_7) Or KeyboardPushed(#PB_Key_Pad7)
kchar="7"
ElseIf KeyboardPushed(#PB_Key_8) Or KeyboardPushed(#PB_Key_Pad8)
kchar="8"
ElseIf KeyboardPushed(#PB_Key_9) Or KeyboardPushed(#PB_Key_Pad9)
kchar="9"
ElseIf KeyboardPushed(#PB_Key_Minus)
kchar="-"
ElseIf KeyboardPushed(#PB_Key_Equals)
kchar="="
ElseIf KeyboardPushed(#PB_Key_Slash)
kchar="/"
ElseIf KeyboardPushed(#PB_Key_BackSlash)
kchar="\"
ElseIf KeyboardPushed(#PB_Key_LeftBracket)
kchar="["
ElseIf KeyboardPushed(#PB_Key_RightBracket)
kchar="]"
ElseIf KeyboardPushed(#PB_Key_SemiColon)
kchar=";"
ElseIf KeyboardPushed(#PB_Key_Apostrophe)
kchar="'"
ElseIf KeyboardPushed(#PB_Key_Period) Or KeyboardPushed(#PB_Key_PadComma)
kchar="."
ElseIf KeyboardPushed(#PB_Key_Comma)
kchar=","
ElseIf KeyboardPushed(#PB_Key_Q)
kchar="q"
ElseIf KeyboardPushed(#PB_Key_W)
kchar="w"
ElseIf KeyboardPushed(#PB_Key_E)
kchar="e"
ElseIf KeyboardPushed(#PB_Key_R)
kchar="r"
ElseIf KeyboardPushed(#PB_Key_T)
kchar="t"
ElseIf KeyboardPushed(#PB_Key_Y)
kchar="y"
ElseIf KeyboardPushed(#PB_Key_U)
kchar="u"
ElseIf KeyboardPushed(#PB_Key_I)
kchar="i"
ElseIf KeyboardPushed(#PB_Key_O)
kchar="o"
ElseIf KeyboardPushed(#PB_Key_P)
kchar="p"
ElseIf KeyboardPushed(#PB_Key_A)
kchar="a"
ElseIf KeyboardPushed(#PB_Key_S)
kchar="s"
ElseIf KeyboardPushed(#PB_Key_D)
kchar="d"
ElseIf KeyboardPushed(#PB_Key_F)
kchar="f"
ElseIf KeyboardPushed(#PB_Key_G)
kchar="g"
ElseIf KeyboardPushed(#PB_Key_H)
kchar="h"
ElseIf KeyboardPushed(#PB_Key_J)
kchar="j"
ElseIf KeyboardPushed(#PB_Key_K)
kchar="k"
ElseIf KeyboardPushed(#PB_Key_L)
kchar="l"
ElseIf KeyboardPushed(#PB_Key_Z)
kchar="z"
ElseIf KeyboardPushed(#PB_Key_X)
kchar="x"
ElseIf KeyboardPushed(#PB_Key_C)
kchar="c"
ElseIf KeyboardPushed(#PB_Key_V)
kchar="v"
ElseIf KeyboardPushed(#PB_Key_B)
kchar="b"
ElseIf KeyboardPushed(#PB_Key_N)
kchar="n"
ElseIf KeyboardPushed(#PB_Key_M)
kchar="m"
ElseIf KeyboardPushed(#PB_Key_Space)
kchar=" "
EndIf
EndIf
If KeyboardPushed(#PB_Key_LeftShift) Or KeyboardPushed(#PB_Key_RightShift)
Select kchar
Case "/"
kchar="?"
Case "."
kchar=">"
Case ","
kchar="<"
Case ";"
kchar=":"
Case "'"
kchar=Chr(34)
Case "["
kchar="{"
Case "]"
kchar="}"
Case "\"
kchar="|"
Case "`"
kchar="~"
Case "1"
kchar="!"
Case "2"
kchar="@"
Case "3"
kchar="#"
Case "4"
kchar="$"
Case "5"
kchar="%"
Case "6"
kchar="^"
Case "7"
kchar="&"
Case "8"
kchar="*"
Case "9"
kchar="("
Case "0"
kchar=")"
Case "-"
kchar="_"
Case "="
kchar="+"
EndSelect
If Asc(kchar) >= $61 And Asc(kchar) <= $7A
kchar=UCase(kchar)
EndIf
EndIf
If kchar<>""
lastKeyTypeMs=ElapsedMilliseconds()
EndIf
ProcedureReturn kchar
EndProcedure
1. Must be 3.94 compatible (Optional 4.0)
2. Must work similar to how normal textgadgets work when detecting each key
3. Must be cross-platform
4. Must detect keypresses on pushed, not released.
[edit] had to disable html in this post