Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to toggle the caps lock LED with QBasic?

Status
Not open for further replies.

JohnJohn20

Advanced Member level 4
Full Member level 1
Joined
Feb 2, 2012
Messages
111
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,377
Hi. QBasic is quite dated but I hope someone out there can help me with this.

I wrote this code to toggle the caps lock LED on my computer keyboard:

100
DEF SEG=0
POKE &H417, 0
DEF SEG
LINE INPUT "Lowercase", text$

DEF SEG=0
POKE &H417, 64
DEF SEG
LINE INPUT "Uppercase", text$

GOTO 100

And it works great. Whenever I hit return it toggles between caps lock on and caps lock off.

However, when I wrote this next code to do the toggling automatically:-
100
DEF SEG=0
POKE &H417, 0
DEF SEG
PRINT "Lowercase"
CALL OneSecDelay

DEF SEG=0
POKE &H417, 64
DEF SEG
PRINT "Uppercase"
CALL OneSecDelay

GOTO 100

The LED doesn't get toggled.

I did notice that if the CAPS LOCK is on AND "Lowercase" has just appeared on the screen AND I hit any key on the keyboard then the CAPS LOCK LED will toggle. (Also will if the CAPS LOCK is off AND "Uppercase" has just appeared on the screen)

That is, it seems, for the POKE command to have an effect on the computer I need to wake it up by typing a key (mouse buttons have no effect).

What can I do to make the auto toggling code work without any user input?

FYI My plan is to use the circuit from a USB keyboard to control things like motors and lights from my computer via the usb port similar to what can be done with a parallel port. Most keyboards have the 3 leds (outputs) and lots of inputs.

Thanks.
 

I don't know for sure but you may need to call a routine which reads the keyboard queue. For the reason that normally we have to press CAPS LOCK to make the led go on and off. Until you press a key, the computer may not realize its status has changed and needs to be updated. Then you press a key, it detects a keyboard press, and it checks whether caps are on or off by PEEKing &H417.

You may need to place a character code in the queue and then call the routine... or somehow duplicate the same result you achieve when you press a key at the correct moment in time.

Also, I suspect that the PRINT command does other routines in addition to print text & execute a carriage return & line feed. One of these routines may counteract what you want to achieve. Or maybe it neglects to PEEK &H417.

On the other hand LINE INPUT displays text and waits for you to press Return, which calls a different series of routines, which probably includes PEEKing &H417.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top