Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:57 07 Oct 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Problems with USB keyboard (keydown and inkey)

Author Message
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 07:27am 02 Oct 2025
Copy link to clipboard 
Print this post

Hello all!

Maybe this is more a question for Peter, but maybe I am blind and anyone knows a solution.

I am heavily working on the translation of my journal/diary program including GUIs for the PicoMite HDMI (USB!) version, because I started this project in pure German.

The Problem: I was using the PicoMite HDMI PS/2 version, in this version I am able to
read in the raw ASCII value via the command:


MM.INFO(PS2) '(Reports the last raw message received on the PS2 interface if enabled.)


Why would I do this? Simply because this allows me to read in the raw key of German Umlaute (ÄäÜüÖöß) and map then to a custom font made by Martin, which has all the German Umlaute in it.

So for converting this already huge program, I have written, to the USB version, I desperatly need to read in the raw USB keys of those Umlaut-Keys, too. I can't find any command for this. I was optimistic that:


keyDown(n)


will do the trick, for the USB version - but it doesn't show anything when I press on my German Keyboard "ÄÜüÖöß" - so there is no solution for me, to translate my software for the German USB version (and after that to the english USB version).

I really hope there is a solution for that, if not I have to stick to the PS/2 version - which is ok, but sad, since Peter fixed the missing keys on the USB version many iterations ago  

Only for the interested, a short program description:
---------------------------------------------------------------

Here are some images of the already finished (german version) of my diary/journaling
software, it also includes a text editor, excessive graph options to show different parameters. And it doesn't stop there: you have in fact three different working areas:

diary/journal = German = "Tagebuch"
health        = German = "Gesundheit"
notebook      = German = "Notizbuch"

in every area (German = "Bereich") you have different visualisation parameters for the graph. For example you can track your: pulse, blood pressure, stress, words you have written on the specific entry, and you can even add own comparison parameters.
There is a search function, which allows to search a whole month for specific words.

The program is split into six different (chained) programs.

-----------------------------------------------------------------









Greetings
Daniel
Edited 2025-10-02 17:50 by Amnesie
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10453
Posted: 09:10am 02 Oct 2025
Copy link to clipboard 
Print this post

Try this


PicoMite.zip


MM.USB will give you the raw code of the last key pressed. If you also need to interpret this with modifier keys you can get these using KEYDOWN(7)
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 12:52pm 02 Oct 2025
Copy link to clipboard 
Print this post

Hi Peter,

with this version I can indeed catch the "Umlaute" keys but the command

  Quote  
MM.USB


behaves different compared to "MM.Info(PS2)".

MM.USB always shows the last pressed key, MM.Info(PS2) in contrast "resets" the key value.

The problem now is, when using:

MM.USB (to detect the ÄäÜüÖöß) I also have to use KEYDOWN(7) for detecting the shift modifier.

But if I use both in combination, there is a huge latency and missing keypresses again.

The latency / missing key-problem already occurs when I use something like:


If keydown(7)=8 Then
shift_pressed=1
Else
shift_pressed=0
EndIf


So the idea would be, to make the behavior of the "MM.USB" like the "MM.Info(PS2)"  
One wouldn't need the keydown(7), which slows things down, and I also don't have to set a flag (or similar) to reset the raw-keycode from MM.USB, since it always shows the last keypress value. I think all this in combination slows things down?

Greetings
Daniel
Edited 2025-10-02 22:53 by Amnesie
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 01:07pm 02 Oct 2025
Copy link to clipboard 
Print this post

Here is a small testprogram, I don't even use German Umlaute in this case but there are a lot of missing keypresses (if I delete the keydown(7) - everyting works fine).
What I want to show with this example is, that KeyDown(7) is causing a latency issue (if this is the right term)...


Option explicit
Dim String lines$(10) length 41
Dim String a
Dim integer myLine=1, ps2_pause=250
Dim integer shift_pressed=0, USBkey, last_USBkey, flag=0
CLS

Do
 key_input: a=Inkey$
 If USBkey <> MM.USB Then 'store the previous pressed key
   last_USBkey = USBkey    
 EndIf

If KeyDown(7)=8 Then
   shift_pressed=1
 Else
   shift_pressed=0
 EndIf


 USBkey = MM.USB     'get USB keystroke

 If a="" Then GoTo key_input         'get new keystroke
 EndIf

 'New line handling
 If Len(lines(myLine))>=41 Then
   myLine=myLine+1
 EndIf
 lines(myLine) = lines(myLine) + a     'add new char to string array
 'Show Text
 Text 0,13+myLine*16,lines(myLine),,9,1,RGB(green)
Loop

' font_Classic
' Font type    : Full (224 Characters)
' Font size    : 8x8 pixels
' Memory usage : 1792
DefineFont #9
E0200808
00000000 00000000
18181818 00180018
006C6C6C 00000000
6CFE6C6C 006C6CFE
7CD07E10 0010FC16
3058AC46 0084CA64
76386C38 0076CCDC
00301818 00000000
30303018 00183030
18181830 00301818
7C385400 00005438
7E181800 00001818
00000000 30181800
7C000000 00000000
00000000 00303000
180C0602 00C06030
D6CEC67C 007CC6E6
18183818 003C1818
3C0606FC 00FEC060
3C0606FC 00FC0606
D8D8C0C0 001818FE
FCC0C0FE 00FC0606
FCC0C07C 007CC6C6
180C06FE 00303018
7CC6C67C 007CC6C6
7EC6C67C 007C0606
18180000 00181800
18180000 30181800
6030180C 000C1830
007C0000 0000007C
0C183060 00603018
1C0606FC 00300030
AA9A423C 003C409C
C6C6C67C 00C6C6FE
FCC6C6FC 00FCC6C6
C0C0C67C 007CC6C0
C6C6C6FC 00FCC6C6
F8C0C0FE 00FEC0C0
F8C0C0FE 00C0C0C0
CEC0C67C 007EC6C6
FEC6C6C6 00C6C6C6
1818183C 003C1818
0C0C0C1E 0078CCCC
F0D8CCC6 00C6CCD8
C0C0C0C0 00FEC0C0
D6FEEEC6 00C6C6C6
DEF6E6C6 00C6C6CE
C6C6C67C 007CC6C6
C6C6C6FC 00C0C0FC
C6C6C67C 0076CCDE
C6C6C6FC 00C6C6FC
7CC0C07E 00FC0606
1818187E 00181818
C6C6C6C6 007CC6C6
C6C6C6C6 0010386C
D6C6C6C6 00C6EEFE
386CC6C6 00C6C66C
3C666666 00181818
30180CFE 00FEC060
30303038 00383030
3060C080 00060C18
18181838 00381818
00663C18 00000000
00000000 00FE0000
00183030 00000000
067C0000 007EC67E
C6FCC0C0 00FCC6C6
C67C0000 007CC6C0
C67E0606 007EC6C6
C67C0000 007CC0FE
7C30301C 00303030
C67E0000 7C067EC6
C6FCC0C0 00C6C6C6
18380018 003C1818
18380018 F0181818
CCC6C0C0 00C6CCF8
30303030 00183030
D6EC0000 00C6C6D6
C6FC0000 00C6C6C6
C67C0000 007CC6C6
C6FC0000 C0C0FCC6
C67E0000 06067EC6
E6DC0000 00C0C0C6
C07E0000 00FC067C
307C3030 001C3030
C6C60000 007EC6C6
C6C60000 0010386C
C6C60000 006ED6D6
6CC60000 00C66C38
C6C60000 7C067EC6
0CFE0000 00FE6038
60303018 00183030
18181818 00181818
0C181830 00301818
CCD66600 00000000
C66C3810 00FE8282
FEC0603E 003E60C0
28FEAAEE 00EEAAFE
00000000 00603030
3C18180E 00F01818
00000000 00D86C6C
00000000 00540000
107C1010 00101010
107C1010 0010107C
00CC7830 00000000
2050A844 0014AA54
C07E386C 00FC067C
C0603000 003060C0
9C90907E 007E9090
02010000 003E0A05
9454B47C 001E14F4
C6C6FE00 0000FEC6
C6C6FE00 0000FEC6
00183030 00000000
00301818 00000000
00366C6C 00000000
00D86C6C 00000000
7C380000 00000038
7C000000 00000000
FE000000 00000000
587C3400 00000000
54545CF4 00000000
603C1028 00780C38
060C1800 00180C06
B66C0000 006EB0BE
C6C6FE00 0000FEC6
C6C6FE00 0000FEC6
3C660066 00181818
00000000 00000000
18180018 00181818
603C1818 18183C60
7830301E 00FE6030
6C6CBA00 000000BA
7C386CC6 00107C10
00181818 00181818
48B0E07C 00F80C34
00006C6C 00000000
A2BA4438 003844BA
241C0418 0000001E
6C6C2412 00001224
FE000000 00000202
7C000000 00000000
B2AA7438 003844AA
0000FE00 00000000
18242418 00000000
187E1818 007E0018
806010E0 000000F0
10E010E0 000000E0
00603030 00000000
7E363636 0080C062
CACACA7E 000E0A7A
30300000 00000000
20000000 00300830
20A06020 00000020
6C6C6C38 00000038
36362448 00004824
30988C86 028ECA68
30988C86 0E84C26C
38CC26C2 02CE6AF8
70180018 007CC6C0
C67C3860 00C6FEC6
C67C380C 00C6FEC6
C67C2810 00C6FEC6
C67C7ABC 00C6FEC6
C67C006C 00C6FEC6
C67C2838 00C6FEC6
FC90503E 009E9090
C0C0C67C 70187CC6
C0FE1830 00FEC0FC
C0FE3018 00FEC0FC
C0FE6C38 00FEC0FC
C0FE006C 00FEC0FC
18001830 00181818
30003018 00303030
30006C38 00303030
303000CC 00303030
F666667C 007C6666
E6005834 00CEDEF6
C67C1830 007CC6C6
C67C3018 007CC6C6
C67C6C38 007CC6C6
C67CBC6E 007CC6C6
C67C006C 007CC6C6
183C6600 0000663C
D6CE6C3A 00B86CE6
C6C61830 007CC6C6
C6C63018 007CC6C6
C6006C38 007CC6C6
C6C6006C 007CC6C6
66665608 0018183C
24382070 00702038
CCC6C67C 80DCC6C6
067C1830 007EC67E
067C3018 007EC67E
067C6C38 007EC67E
067CDC76 007EC67E
067C006C 007EC67E
067C2838 007EC67E
12EC0000 007E907E
C07E0000 70187EC0
C67C1830 007CC0FE
C67C3018 007CC0FE
C67C6C38 007CC0FE
C67C006C 007CC0FE
38001830 003C1818
38003018 003C1818
38006C38 003C1818
1838006C 003C1818
7C2C1874 0078CCCC
FC005834 00C6C6C6
7C001830 007CC6C6
7C003018 007CC6C6
7C006C38 007CC6C6
7C005834 007CC6C6
C67C006C 007CC6C6
7E001800 00001800
D6CE3C02 00807CE6
C6C61830 007EC6C6
C6C63018 007EC6C6
C6006C38 007EC6C6
C6006C00 007EC6C6
C6C63018 7C067EC6
4C7840C0 00E04078
C6C6006C 7C067EC6
End DefineFont


Edited 2025-10-02 23:13 by Amnesie
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10453
Posted: 04:03pm 02 Oct 2025
Copy link to clipboard 
Print this post

keydown clears the input buffer so you are probably waiting for a repeat. It is not intended that you use keydown with input$. Keydown is intended to give an instantaneous view of anything that is pressed at the instant it is called - the main purpose is for things like game input. MM.USB will likewise give the last key pressed.

If I understand what you are trying to do, you probably don't need MM.USB at all.
Keydown[1] gives you the last key pressed as an ascii character and keydown[7] tells you if any modifier keys are pressed. Together they should allow you program to work out any accented character. Just don't use input$ at all.

You will have to poll keydown on a regular basis and deal with checking for a change to indicate keyup and implement autorepeat if you need it in your Basic program

Just run a tight loop outputting keydown[1] and keydown[7] so you can see how it works
Edited 2025-10-03 02:21 by matherp
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 04:52pm 02 Oct 2025
Copy link to clipboard 
Print this post

  matherp said  
If I understand what you are trying to do, you probably don't need MM.USB at all.
Keydown[1] gives you the last key pressed as an ascii character and keydown[7] tells you if any modifier keys are pressed. Together they should allow you program to work out any accented character. Just don't use input$ at all.


Hi Peter, thanks for quick reply!

I already did it like you suggested, but I think you can't try this because you haven't a german keyboard. The whole reason asking for something like MM.USB is the fact that:

keydown(1) does NOT respond to the german keyboard keys "äöüß" so there is nothing I could further process or re-map.

In other words:


Do
Print keyDown(1)
Loop


does not print anything if I hit "ä","ü","ö","ß"

The solution (or at least part of it) is your new function MM.USB, only here I have the chance to "catch" any output from the mentioned keys.

So my only chance is to do the following:

1. read the raw key (ä,ö,ü,ß) via MM.USB
2. check via keyDown(7) if SHIFT-key is pressed
3. manually map the "ä,ö,ü,ß / Ä, Ü, Ö, ?" to a custom FONT, which Martin kindly created

Problem: as soon as I use "keyDown(7)" everything is "laggy", keypresses are skipped or ignored.

With PS/2 I did the same (only of course with MM.Info(PS2)) and it works just perfect! No missed keys, no latency at all. I hoped, that this workaround would also work for the USB version. This way one could implement ANY keyboard layout.

Greetings
Daniel
Edited 2025-10-03 02:56 by Amnesie
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8156
Posted: 06:00pm 02 Oct 2025
Copy link to clipboard 
Print this post

PS2 is *way* different to USB, which loads the system with all sorts of processing that you don't always want.  :(
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10453
Posted: 06:11pm 02 Oct 2025
Copy link to clipboard 
Print this post

Problem: as soon as I use "keyDown(7)" everything is "laggy", keypresses are skipped or ignored.


That makes no sense unless there is something else going on. All keydown does is read the input buffer until it is empty which should be pretty much instantaneous and then return the contents of an array which is filled in the background by the USB keyboard handler.
Are you saying the function takes a long time to return or that it is a long time before the modifier key is seen?
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 07:56am 03 Oct 2025
Copy link to clipboard 
Print this post

  matherp said  
Are you saying the function takes a long time to return or that it is a long time before the modifier key is seen?


Hi Peter,

The problem seems to only occur, when I use downKey(7) together with inkey - which isn't ideal, as you've suggested. So I am figuring out how to properly solve the conversion from PS/2 to USB, since MM.USB is much different from MM.Info(ps2).

As said, the MM.USB is needed because downkey(1) does NOT catch any code on german keyboard, when pressing ä,ö,ü,ß

So now the code will be much more complicated, compared to the ps/2 version of the picoMite. I am still on it. But as said: MM.USB is absolutly necessary - without it, there is no way of catching any of the "Umlaute".

Greetings
Daniel
Edited 2025-10-03 17:56 by Amnesie
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 09:37am 03 Oct 2025
Copy link to clipboard 
Print this post

Hmm..

I am playing for hours now and have no success + the code will be much much more complicated because I have to do everything manually:

1. catch the raw USB code for the german "Umlaut" via MM.USB (downkey(1) does not do this for those keys!)

2. get a constant feedback of the SHIFT modifier via downkey(7)

3. map all cases for the raw USB code to ASCII values and then link them to the
corresponding custom Font character

My best guess is that all this takes too much time or processing power. There is always a missing character and the already existing program code would be hugely more complicated.

My wish would be a function like MM.info(ps2) that behaves exactly like this, so that there is no need for:

1. checking the modifier via a different function
2. resetting the value of the pressed key again and again "by hand" to zero

USB is so much more complicated...

Greetings
Daniel
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10453
Posted: 09:51am 03 Oct 2025
Copy link to clipboard 
Print this post

If you provide a list of the USB scan codes for all relevant keys and required modifiers associated I will see if I can do anything. I just need all the required unique pairings I don't care what they mean

e.g.

code modifier
0x87  ALT
0x87  none
...
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10453
Posted: 10:48am 03 Oct 2025
Copy link to clipboard 
Print this post

Is this correct


 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 07:57pm 03 Oct 2025
Copy link to clipboard 
Print this post

Hi Peter,

Sorry for my late respond, just came home.

Yes your list is correct. For example, If I type in your test-firmware via:

Print MM.USB (and pressing "ü")

I get: 47, which is "0x2F"

Etc...

Would be Amazing , if you could work something out for a simple solution or some function which acts like MM.info(ps2)  

If you need some more testings or info, I will do my best.

Greetings
Daniel
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2755
Posted: 09:34pm 03 Oct 2025
Copy link to clipboard 
Print this post

Seen this in PicoMite V6.01.00 betas thread?
  matherp said  V6.01.00b18

Minor internal changes
DE USB keyboard should now return codes 200-209 for accented keyboard characters with normal input (input$/inkey$)
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 703
Posted: 06:26am 04 Oct 2025
Copy link to clipboard 
Print this post

Oh, I missed that! Thank you for the hint. I'll give it a try  
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025