Jump to content



Photo
* * * * * 1 votes

The Truth About Getkey


  • Please log in to reply
14 replies to this topic

#1 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 14 May 2012 - 12:39 AM

OK, lately a few of you seemed to be having problems with getkey. I finally ran I series of tests on my calc and came to the following conclusions:

Getkey does not store the last key pressed.

In this thread, Khoraski and I came to the false conclusion that Getkey does not return to zero after a key is pressed. This is false. I discovered that because I did this small test program:

While 1
ClrText
Locate 1,1,Getkey
WhileEnd

Try pressing any key. You will notice that it will show the value of the key only while the key is being pressed. The reason that I thought that it was not returning to zero afterwards was because my program was setup like this:

"Test"? -> V
While not Getkey
WhileEnd
"Done"

It would go straight to "Done" without looping. I have discovered why that is. When you finish inputting in the test prompt, you press EXE. You do not release the EXE key immediately, though. So Getkey is true and breaks from the loop. How do we fix this? I do it by adding a a little delay:

Deprecated. See the edit below.

"Test"? -> V

//begin delay
2 -> I
While I>0
I-1 -> I
WhileEnd
//end delay

While not Getkey
WhileEnd
"Done"

If you have any more problems with this function, feel free to post here so I can help figure out whats going on. ;)






EDIT:

cfxm provided a very good piece of code that works better than my delay.
"TEST"? -> V
While Getkey
WhileEnd
Do
Getkey
LpWhile Not Ans // Or any specific key

The first loop waits for you to release the key, and the second waits for you to press a new one.

EDIT2:

3298 provided this useful code for checking if a key was pressed. However, the original author was someone else.

While 1
Do
Getkey -> K
LpWhile K=0
If K=27
Then ...
IfEnd
While Getkey=K
WhileEnd
WhileEnd

The Do-LpWhile loop waits for a key and stores it in K, the While loop at the end waits until the key is released.

Source

#2 Naga

Naga

    Newbie

  • Members
  • Pip
  • 25 posts
  • Gender:Male
  • Location:chennai,India

  • Calculators:
    Casio 9860 GII

Posted 14 May 2012 - 03:40 AM

Nice examples.

Here is my code.


?->K

Do:Getkey

Lpwhile Not Ans

Ans=79(F1)=>K+1->K

Ans=69(F2)=>K+2->K

Locate 1,1,K

First am inputting K value.

If I press F1 it should add 1 to the K value and then print the result.

Suppose if I press the number 10 it should take 10 as input and then display the value.

How to solve this?

#3 noname11

noname11

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 314 posts
  • Gender:Not Telling

Posted 14 May 2012 - 12:53 PM

This is my solution when reading keys:
While Getkey
WhileEnd
Do
Getkey
LpWhile Not Ans // Or any specific key

  • Naga and FrankJ like this

#4 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 14 May 2012 - 01:55 PM

This is my solution when reading keys:

While Getkey
WhileEnd
Do
Getkey
LpWhile Not Ans // Or any specific key


That is very clever. I see how that works. The first loop will not break if the key is still pressed and the second waits for a new key. I am going to put this in the original post. ;)

Nice examples.

Here is my code.


?->K

Do:Getkey

Lpwhile Not Ans

Ans=79(F1)=>K+1->K

Ans=69(F2)=>K+2->K

Locate 1,1,K

First am inputting K value.

If I press F1 it should add 1 to the K value and then print the result.

Suppose if I press the number 10 it should take 10 as input and then display the value.

How to solve this?


Using CFXM's method:

?->K
// as long as the EXE button is pressed, the loop below will continue.
While Getkey
WhileEnd
// after EXE is released, this loop runs
Do:Getkey
Lpwhile Not Ans

Ans=79(F1)=>K+1->K

Ans=69(F2)=>K+2->K

Locate 1,1,K


#5 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 27 October 2012 - 09:40 PM

Updated the original post to show 3298's solution for checking if a key is pressed.

#6 3298

3298

    Casio Addict

  • Members
  • PipPipPip
  • 79 posts
  • Gender:Male
  • Location:Germany

  • Calculators:
    fx-9750G Plus
    Algebra FX 2.0 (ROM 1.03,broken)
    HP 50G

Posted 28 October 2012 - 11:23 AM

Actually, that was not my code snippet. When I got my first Casio calc in 2006, I read some programs written by other people and saw something similar. I considered it useful, optimized it a bit and used it myself. This is just the result of my optimization.

#7 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 28 October 2012 - 03:41 PM

Oh, really? I suppose you wouldn't know who originally authored it then?

Anyway, you were the one who provided the code, so I will change the wording in the post accordingly ;)

#8 3298

3298

    Casio Addict

  • Members
  • PipPipPip
  • 79 posts
  • Gender:Male
  • Location:Germany

  • Calculators:
    fx-9750G Plus
    Algebra FX 2.0 (ROM 1.03,broken)
    HP 50G

Posted 03 November 2012 - 03:37 PM

I think it was in a blackjack game distributed via calc<->calc cable in my class. Translating all the strings and implementing a save/load functions for this game were the first things I did with CasioBasic after some HelloWorld-type experiments. I do not have that copy anymore, but I believe the first screen of that game showed "P. Geißler" in the small font (The ß was actually a B, that's why I remembered it).
But anyway, I have looked at other programs later and found similar things in them. Apparently this technique was a commonly used one back then.
I found an example in the DCF's archive: http://casiofans.de/...1&t=2067#p11636

#9 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 03 November 2012 - 03:39 PM

You were able to do calc <=> calc communications with BASIC?

#10 3298

3298

    Casio Addict

  • Members
  • PipPipPip
  • 79 posts
  • Gender:Male
  • Location:Germany

  • Calculators:
    fx-9750G Plus
    Algebra FX 2.0 (ROM 1.03,broken)
    HP 50G

Posted 03 November 2012 - 03:44 PM

No, but the program was distributed from one pupil to the next (using the standard link menu). When I found the Send( and Receive( commands, I tried to implement a multiplayer part for the game, but of course I failed. Later I learned why: those commands were present for the EA-100, not for calc<->calc communication.

#11 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 03 November 2012 - 05:37 PM

Oh, ok, so they were not playing the blackjack game calc <=> calc, it was just distributed that way, right?

#12 FrankJ

FrankJ

    Newbie

  • Members
  • Pip
  • 4 posts
  • Gender:Male

  • Calculators:
    CASIO fx-9750GII (Hand-Me-Down From Sister)
    CASIO fx-82AU PLUS UU

Posted 09 January 2021 - 12:34 AM

I wrote a more understandable and simple program.

150➡T
While T>0
T-1➡T
WhileEnd
While Getkey=0
WhileEnd
Getkey➡A
A




Edited by FrankJ, 09 January 2021 - 12:36 AM.


#13 r0773n

r0773n

    Newbie

  • Members
  • Pip
  • 7 posts
  • Gender:Male

  • Calculators:
    Hacked fx-9750GII-2 (9860GII OS)

Posted 23 February 2021 - 01:46 PM

This is my solution when reading keys:

While Getkey
WhileEnd
Do
Getkey
LpWhile Not Ans // Or any specific key

When would you need to use the first bit (While:Getkey:WhileEnd) in a program? surely the second bit is enough?

(I understand what it does, just wondered about using it)


Edited by r0773n, 23 February 2021 - 01:48 PM.


#14 HappyCalc

HappyCalc

    Casio Addict

  • Members
  • PipPipPip
  • 67 posts
  • Gender:Male
  • Location:Germany
  • Interests:Programming, On-Calc Programming(C.Basic), Gaming, Origami, Eating Chocolate

  • Calculators:
    fx-9860GII-2
    fx-CG50

Posted 31 October 2021 - 08:47 AM

When would you need to use the first bit (While:Getkey:WhileEnd) in a program? surely the second bit is enough?
(I understand what it does, just wondered about using it)


It's just to keep the program from the key pressed to start it. If you press exe in the menu, the program would read that you pressed exe.

#15 piu58

piu58

    Casio Freak

  • Members
  • PipPipPipPip
  • 145 posts
  • Gender:Male

  • Calculators:
    Casio Graph 90+E, Casio fx-CG20

Posted 05 November 2021 - 03:30 PM

Thsi discussion reminds me the time when I wrote a machine code program for my ZX81 for reading the keyboard. After reading a key, I had always to wait if the key is released. Same thing here.


  • flyingfisch likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users