Jump to content
IGNORED

Simple method of detecting Upper or Lower Case input with Extended BASIC


dgrissom

Recommended Posts

Years ago, during a TIBUG -- Birmingham User Group meeting, my close friend Barron gave me this tip on detecting a key press no matter where the ALPHA-LOCK was set.

Until recently, I could not remember the syntax and either warned the user to set the ALPHA-LOCK or tried to catch both the upper and lower key codes in my Extended BASIC code. Typically, I use this in simple single key menus.

 

During one of our recent Zoom meeting, I asked our attendees if they knew about about this.  The answer was no, however, I received some good suggestions that helped me ferret out the correct syntax.  I was able to demo the solution before the end of our meeting.  

 

If you take a returned keypress ASCII value(K) and logical " OR " it with 32 you will always get the lowercase character code.  Example: Using the letter "A" where K=65: (K OR 32) returns 97 this equals "a".  If the returned value is K=97 ("a") this will also return 97!

 

If you subtract 32 from the above returned value you will get the uppercase character or "A".  (K OR 32)-32

With a small amount of code change you may be able to turn this into a UCASE$ or LCASE$ using a function or sub procedure.

 

Example Menu Test (Paste this into CLASSIC 99 using Extended BASIC)
 

100 ! Extended BASIC Only
110 CALL CLEAR
120 PRINT
130 PRINT "Logical Case Conversion"
140 PRINT
150 PRINT "ACII 'OR' 32 method"
160 PRINT :: PRINT
170 PRINT "CALL KEY Test..."
180 PRINT :: PRINT :: PRINT
190 PRINT "PRESS 'ESDX'"
200 PRINT "ALPHA-LOCK can be UP or DOWN"
210 PRINT "-- Try it both ways!"
220 PRINT "TESTS UPPERCASE AS INPUT!" :: PRINT
230 CALL KEY(0,K,S)
240 IF S=0 THEN 230
250 PRINT "Pressed: '";CHR$(K);"' OR ASCII:";K :: PRINT
260 IF ((K OR 32)-32)=69 THEN PRINT " -UP-" :: GOTO 300
270 IF ((K OR 32)-32)=88 THEN PRINT " -DOWN-" :: GOTO 300
280 IF ((K OR 32)-32)=83 THEN PRINT " -LEFT-" :: GOTO 300
290 IF ((K OR 32)-32)=68 THEN PRINT " -RIGHT-" ELSE PRINT "TRY AGAIN!"
300 GOTO 180


I hope this might be useful to others. Again, this only applies to "Extended BASIC".

  • Like 4
Link to comment
Share on other sites

Ok I am mystified about this post.

Key scan mode 3 is UPPER CASE ONLY

If you type:

100 CALL KEY(3,K,S) :: IF S=0 THEN 100 ELSE PRINT K :: GOTO 100

 

Even more easy is RXB type:

CALL KEY("",3,K,S) :: PRINT K

 

And added new command CALL ALPHALOCK(X) :: PRINT X

This would tell you if ALPHALOCK key is up or down

 

  • Like 3
Link to comment
Share on other sites

While this is a worthwhile observation for certain niche situations (where one previously used CALL key via Key Unit 0, but now want to treat the value in a case-insensitive manner), I guess I don't really understand why one would use Key Unit 0 - an explicitly case-sensitive key scan - for ESDX input, if one specifically desires a case-insensitive key scan (which is otherwise also available).  Key Unit 1 will just ignore the state of the caps lock key with no actual work.  And another nice thing about Key Unit 1 is that it returns values from 0-6 for keys in the ESDX area (e.g., the WASD keys return 1,2,3,4 while ESDX returns 0,2,3,5) rather than ASCII values (WASD returns 87,65,83,68 while ESDX returns 69,83,68,88).  So even case aside these tend to be much more directly useful in their unmodified state (for selecting array values, screen locations, ON GOSUB destinations, etc.)

  • Like 3
Link to comment
Share on other sites

Another possibility is this:

10 CALL KEY(3,K,S)::DISPLAY AT(24,1):K::GOTO 10

This will always read the keys as upper case.

 

Another nifty trick is:

10 CALL KEY(3,K,S)

20 INPUT A$::GOTO 20

This will only input upper case characters regardless of the alpha lock status.

 

This will work in TI BASIC as well, but of course you cannot use multiple statements in a line.

 

Edited by senior_falcon
  • Like 3
Link to comment
Share on other sites

In all the decades I've been programming on the TI, I never once thought of using anything other than the 0 keyboard scan... Just thinking about all the wasted code space trying to trap upper case input over the years! Damn... 🥶 

  • Like 1
  • Haha 1
Link to comment
Share on other sites

13 hours ago, senior_falcon said:

Another possibility is this:

10 CALL KEY(3,K,S)::DISPLAY AT(24,1):K::GOTO 10

This will always read the keys as upper case.

 

Another nifty trick is:

10 CALL KEY(3,K,S)

20 INPUT A$::GOTO 20

This will only input upper case characters regardless of the alpha lock status.

 

This will work in TI BASIC as well, but of course you cannot use multiple statements in a line.

 

What a neat little trick. So until the program encounters a different CALL KEY statement, all input will remain as upper case?

  • Like 1
Link to comment
Share on other sites

I learned about mode 3 only some years ago, as the manuals in German and English both state "Values of 3, 4, and 5 are reserved for possible future uses." 

 

That CALL KEY(3,K,S) also affects a following INPUT was totally new to me ... never stop learning.

 

  • Like 1
Link to comment
Share on other sites

Someone can correct me, but I believe CALL KEY(0,K,S) on the 99/4 was "the whole keyboard", key-unit 1 was the left side and key-unit 2 was the right side.  0 was changed on the 99/4A to mean "use whatever the last key-unit was" but the initialization routine scans the keyboard in all modes at startup, with 5 being the last one used.  Thus, the first time you use key-unit 0, you've actually used 5.  

 

So one way to lock the keyboard in uppercase only mode is to just issue CALL KEY(3,K,S) at the beginning of the program and subsequent INPUTs and CALL KEY(0,K,S) will return only uppercase characters.

  • Like 2
Link to comment
Share on other sites

5 hours ago, Vorticon said:

What a neat little trick. So until the program encounters a different CALL KEY statement, all input will remain as upper case?

On the 4A, the default key scan is mode 5, which is BASIC mode with upper-/lower-case characters available.  Key scan 0 simply uses the last key scan mode explicitly used.  Really, CALL KEY(0,K,S) can wreak havoc if you want to use multiple different key board modes in your program.  Key scan mode 3 is 99/4 mode.  Mode 4 is Pascal mode, which also includes upper-/lower-case characters, but puts FCTN and CTRL keys in different places (essentially swapped) than mode 5.   See page 162 of the 99/4A User Reference Guide.

 

INPUT uses key scan 0, so whatever key scan you used previously will be repeated by INPUT.  (BTW, I do not see where the guide mentions this special ability of INPUT.)

Link to comment
Share on other sites

2 hours ago, Casey said:

Someone can correct me, but I believe CALL KEY(0,K,S) on the 99/4 was "the whole keyboard", key-unit 1 was the left side and key-unit 2 was the right side.  0 was changed on the 99/4A to mean "use whatever the last key-unit was" but the initialization routine scans the keyboard in all modes at startup, with 5 being the last one used.  Thus, the first time you use key-unit 0, you've actually used 5.  

 

So one way to lock the keyboard in uppercase only mode is to just issue CALL KEY(3,K,S) at the beginning of the program and subsequent INPUTs and CALL KEY(0,K,S) will return only uppercase characters.

Yes CALL KEY(0,K,S) will repeat the last key scan used. 3, 4, 5 but will not work with key scan 1 or 2

If you run this program it proves what is going on:

100 CALL KEY(1,K,S)

110 CALL KEY(0,L,T)

120 PRINT K,L

130 GOTO 100

 

Key scan 0 returns same as key scan 3, 4 or 5 but key scan 1 or 2 does not it only returns key scan 5 you can test this using the shift key too.

Link to comment
Share on other sites

Thanks for all the input!

 

I've learned a lot from this thread.  Remember, the method I described originated around 40 years ago before we knew anything the CALL KEY(3,K,S) method. 

 

As much as anything, it was uploaded as a tribute to my late friend and fellow TI user.

 

I wonder if there is a document, that shows other this and other tricks that have been uncovered that would help current BASIC programmers?  I've a number of period books that really don't give many actual tips and tricks.

 

I know that many ideas have already been described in these forums.  However, they can be difficult to to find.

 

Thanks, again!

 

D.Grissom

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...