Author Topic: Playing with keyboard LEDs!  (Read 4216 times)

0 Members and 1 Guest are viewing this topic.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Playing with keyboard LEDs!
« on: March 04, 2020, 10:32:57 pm »
Hi guys, I'm very excited to try the new QB64 version 1.4. These keyboard LEDs functions and statements were something I was needing very badly. I want to create a piece of software "kbdleds.exe" that can be called from command-line with arguments passed like this:

kbdleds.exe c1 n0 s1 (this will make Caps Lock ON, Num Lock OFF, Scroll Lock ON)
kbdleds.exe a0 (this will make all 3 LEDs OFF)
kbdleds.exe ct (this will toggle Caps Lock)

However, I don't know how to read arguments passed via command line, or from a batch file. Help here, please?

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Playing with keyboard LEDs! (SOLVED)
« Reply #1 on: March 04, 2020, 10:37:46 pm »
Nevermind, I figured it out: I can get the parameters with COMMAND$ :-)

Now it's coding time.

FellippeHeitor

  • Guest
Re: Playing with keyboard LEDs!
« Reply #2 on: March 04, 2020, 10:45:32 pm »
Yay! 😁

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Playing with keyboard LEDs!
« Reply #3 on: March 04, 2020, 11:13:49 pm »
If your LEDs are in a line, and you blink them back and forth, the cat will clean your keyboard.
It works better if you plug it in.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Playing with keyboard LEDs!
« Reply #4 on: March 09, 2020, 08:45:53 pm »
I'm having a problem with COMMAND$; whatever is after ">" is discarded and I don't know how to prevent it. I want my program to be able to receive ">nul" after all parameters, so instead of printing it will do the task then go SYSTEM. But since COMMAND$ suppresses everything that comes after ">", I can't get ">nul" into the program.

FellippeHeitor

  • Guest
Re: Playing with keyboard LEDs!
« Reply #5 on: March 09, 2020, 08:49:04 pm »
Anything beyond > is dealt with by your os. Anything before that is yours to manipulate.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Playing with keyboard LEDs!
« Reply #6 on: March 09, 2020, 09:21:22 pm »
Thanks FellippeHeitor, I didn't realize that had to do with the OS. Anyway, here's the code:

Code: QB64: [Select]
  1. param$ = LCASE$(COMMAND$): wrong = 0: silent = 0: _SCREENHIDE
  2. IF RIGHT$(param$, 7) = "-silent" THEN param$ = LEFT$(param$, LEN(param$) - 9): silent = 1
  3. WHILE LEN(param$)
  4.     curr$ = LEFT$(param$, 2): param$ = MID$(param$, 4)
  5.     IF RIGHT$(curr$, 1) <> "n" AND RIGHT$(curr$, 1) <> "c" AND RIGHT$(curr$, 1) <> "s" THEN wrong = 1: EXIT WHILE
  6.     IF LEFT$(curr$, 1) <> "+" AND LEFT$(curr$, 1) <> "-" THEN wrong = 1: EXIT WHILE
  7.     IF curr$ = "+c" THEN _CAPSLOCK ON
  8.     IF curr$ = "-c" THEN _CAPSLOCK OFF
  9.     IF curr$ = "+n" THEN _NUMLOCK ON
  10.     IF curr$ = "-n" THEN _NUMLOCK OFF
  11.     IF curr$ = "+s" THEN _SCROLLLOCK ON
  12.     IF curr$ = "-s" THEN _SCROLLLOCK OFF
  13.  
  14. IF wrong THEN PRINT "Usage: TOGGLEW [+c|-c] [+n|-n] [+s|-s] [-silent]": END
  15.  
  16. PRINT "TOGGLEW 1.0 (c) Filipe Estima"
  17. PRINT "Inspired by TOGGLE (c) 1988 Ziff Communications Co."
  18. PRINT "PC Magazine þ Jeff Prosise": PRINT
  19. PRINT "    CapsLock   :  ";: IF _CAPSLOCK THEN PRINT "On" ELSE PRINT "Off"
  20. PRINT "    NumLock    :  ";: IF _NUMLOCK THEN PRINT "On" ELSE PRINT "Off"
  21. PRINT "    ScrollLock :  ";: IF _SCROLLLOCK THEN PRINT "On" ELSE PRINT "Off"
  22.  

I drew inspiration from TOGGLE, an utility developed by Jeff Prosise for MS-DOS back in 1988, while he worked at PC Magazine. It is just 338 bytes long and does exactly the same as this code.
« Last Edit: March 09, 2020, 09:30:33 pm by FilipeEstima »

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Playing with keyboard LEDs!
« Reply #7 on: March 09, 2020, 09:26:27 pm »
What are the tags I need to use in order to post code that looks like QBASIC code in this forum?

Edit: nevermind, I figured it out.
« Last Edit: March 09, 2020, 09:31:04 pm by FilipeEstima »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Playing with keyboard LEDs!
« Reply #8 on: March 09, 2020, 09:31:52 pm »
What are the tags I need to use in order to post code that looks like QBASIC code in this forum?

It is the QB64 Icon button or
[  code  =  qb64  ]   [  / code ]
without spaces

FellippeHeitor

  • Guest
Re: Playing with keyboard LEDs!
« Reply #9 on: March 09, 2020, 09:46:39 pm »
You may benefit from using COMMAND$ as an array. Try:

Code: QB64: [Select]

FellippeHeitor

  • Guest
Re: Playing with keyboard LEDs!
« Reply #10 on: March 09, 2020, 09:50:54 pm »
I took the liberty:

Code: QB64: [Select]
  1.  
  2.         CASE "-silent": silent = 1
  3.         CASE "+c": _CAPSLOCK ON
  4.         CASE "-c": _CAPSLOCK OFF
  5.         CASE "+n": _NUMLOCK ON
  6.         CASE "-n": _NUMLOCK OFF
  7.         CASE "+s": _SCROLLLOCK ON
  8.         CASE "-s": _SCROLLLOCK OFF
  9.         CASE ELSE: wrong = 1: EXIT FOR
  10.     END SELECT
  11.  
  12. IF silent THEN SYSTEM
  13. IF wrong THEN PRINT "Usage: TOGGLEW [+c|-c] [+n|-n] [+s|-s] [-silent]": SYSTEM
  14.  
  15. PRINT "TOGGLEW 1.0 (c) Filipe Estima"
  16. PRINT "Inspired by TOGGLE (c) 1988 Ziff Communications Co."
  17. PRINT "PC Magazine þ Jeff Prosise": PRINT
  18. PRINT "    CapsLock   :  ";: IF _CAPSLOCK THEN PRINT "On" ELSE PRINT "Off"
  19. PRINT "    NumLock    :  ";: IF _NUMLOCK THEN PRINT "On" ELSE PRINT "Off"
  20. PRINT "    ScrollLock :  ";: IF _SCROLLLOCK THEN PRINT "On" ELSE PRINT "Off"
  21.  
« Last Edit: March 09, 2020, 09:55:51 pm by FellippeHeitor »

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Playing with keyboard LEDs!
« Reply #11 on: March 10, 2020, 07:14:58 am »
Hey, much better! Thanks FellippeHeitor, I didn't have a clue it was possible to write directly to the prompt: never knew _DEST _CONSOLE even existed.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Playing with keyboard LEDs!
« Reply #12 on: March 10, 2020, 08:10:41 am »
I noticed that, since the program is now writing to the console, I don't need the -silent switch anymore. It will work just fine with >nul.

FellippeHeitor

  • Guest
Re: Playing with keyboard LEDs!
« Reply #13 on: March 10, 2020, 08:33:50 am »
Glad I could help 🙂