HP Forums
Reading USBRecv Problem - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Reading USBRecv Problem (/thread-20640.html)



Reading USBRecv Problem - toml_12953 - 10-12-2023 08:53 PM

I'm trying to read the data from a USB keyboard continuously.
Using the program below, I get

USBKBD Error: Bad
argument type

The same USB commands work on the Home screen just fine. All I want to do is stay in the loop until a key is pressed on the keyboard then print the HID data. What am I doing wrong?

Code:
EXPORT USBKBD()
BEGIN
LOCAL A:={0,0,0,0,0,0,0,0};

USBOpen(1084,8467);

WHILE A=={0,0,0,0,0,0,0,0} DO
  A:=USBRecv;
END;

PRINT(A);
END



RE: Reading USBRecv Problem - gehakte_bits - 10-12-2023 09:25 PM

USBRecv() returns an (empty) list.
Don't stick that in 'A'

ie A:={1,2,3} won't work well..


RE: Reading USBRecv Problem - toml_12953 - 10-12-2023 09:52 PM

(10-12-2023 09:25 PM)gehakte_bits Wrote:  USBRecv() returns an (empty) list.
Don't stick that in 'A'

ie A:={1,2,3} won't work well..

I got the following working. Now all I need to do is make a lookup table to print the character typed rather than the HID list. This code will work no matter what keyboard you use. My first draft would only work with one brand/model.

Code:
EXPORT USBKBD()
BEGIN
LOCAL A:={}, B:={};

PRINT();

B:=USBOpen();

USBOpen(B(1,1),B(1,2));

WHILE 1 DO
  REPEAT
    A:=USBRecv;
  UNTIL length(A)>0 AND A(3)≠0
  PRINT(A);
END;

END;



RE: Reading USBRecv Problem - toml_12953 - 10-13-2023 12:01 PM

OK, here's the latest version. It correctly handles A-Z and a-z but no special characters and no Caps Lock.

Code:
EXPORT USBKBD()
BEGIN

  LOCAL A:={};

  PRINT();

  A:=USBOpen();

  USBOpen(A(1,1),A(1,2));

  WHILE 1 DO
    REPEAT
      A:=USBRecv;
    UNTIL length(A)>0 AND A(3)≠0
    //PRINT(A);
    IF A(1)==2 OR A(1)==32 THEN
      PRINT(CHAR(A(3)+61));
    ELSE
      PRINT(CHAR(A(3)+93));
    END;
  END;
END;