Jump to content



Photo
- - - - -

The Truth About Getkey


  • Please log in to reply
10 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 - 01: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 - 04: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 - 01:53 PM

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

  • Naga likes 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 - 02: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 - 10: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
  • 77 posts
  • Gender:Male
  • Location:Germany

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

Posted 28 October 2012 - 12:23 PM

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 - 04: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
  • 77 posts
  • Gender:Male
  • Location:Germany

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

Posted 03 November 2012 - 04: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 - 04:39 PM

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

#10 3298

3298

    Casio Addict

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

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

Posted 03 November 2012 - 04: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 - 06:37 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users