Sorted independent finance guides are full of helpful information on everyday money matters.

TI Nspire CX II and TI Nspire CX II CAS: User Input in Graphics Mode with getKey

TI Nspire CX II  and TI Nspire CX II CAS:  User Input in Graphics Mode with getKey

Introduction

In graphics mode, the TI Nspire CX II cannot use the Text, Request, or RequestStr.  However, with the use of getKey command, we can have the user interact with the program. 

TI Nspire CX II Program keydemo2

This program is a game where the user stops a spinner in hopes to win money or a car.  Good luck!

Define keydemo2()=
Prgm
:Clear 
:Local l,str,k,n
:l:={“$200″,”$300″,”$500″,”$1000″,”CAR”,”Nope.”}
:While getKey(0)≠”enter”
:  Clear 
:  UseBuffer 
:© get key continous execution
:  n:=randInt(1,6)
:  SetColor 0,0,0
:  DrawText 50,25,”PRESS enter TO STOP”
:  If n≤5 Then
:    SetColor 0,128,128
:  Else
:    SetColor 255,0,0
:  EndIf
:© use square brackets for elements 
:© we can clear only dynamic areas
:© but it does not look good
:  DrawText 50,50,l[n]
:  PaintBuffer 
:© usebuffer and paintbuffer allows all objects to be displayed at once, ensuring a smooth transition, can also use wait
:EndWhile
:EndPrgm



TI Nspire CX II Program enterdemo

With the use of getKey, the user enters a number in graphics mode.  This can be used as a template. 

Define enterdemo()=
Prgm
:© goal: develop input in graphics mode
:© use float mode
:setMode(1,1)
:Local str,num,k
:str:=””
:© use initial text
:Clear 
:  SetColor 0,0,0
:  DrawText 0,50,”Press [enter] to stop.”
:
:
:© main loop: enter the numbers
:Loop
:  Clear 
:  UseBuffer 
:  SetColor 0,0,0
:  DrawText 0,50,”Press [enter] to stop.”
:
:  k:=getKey(1)
:  If k=”.” and inString(str,”.”)=0 Then
:    str:=str&”.”
:  ElseIf k=”0″ Then
:    str:=str&”0″
:  ElseIf k=”1″ Then
:    str:=str&”1″
:  ElseIf k=”2″ Then
:    str:=str&”2″
:  ElseIf k=”3″ Then
:    str:=str&”3″
:  ElseIf k=”4″ Then
:    str:=str&”4″
:  ElseIf k=”5″ Then
:    str:=str&”5″
:  ElseIf k=”6″ Then
:    str:=str&”6″
:  ElseIf k=”7″ Then
:    str:=str&”7″
:  ElseIf k=”8″ Then
:    str:=str&”8″
:  ElseIf k=”9″ Then
:    str:=str&”9″
:  ElseIf k=”−” Then
:    str:=string(−1*expr(str))
:  ElseIf k=”del” and dim(str)>0 Then
:    str:=left(str,dim(str)-1)
:
:  ElseIf k=”enter” Then
:© “lock” the number and leave
:  SetColor 0,0,0
:  DrawText 0,100,str
:  PaintBuffer 
:    Exit
:  EndIf
:
:SetColor 0,0,255
:DrawText 0,100,str
:PaintBuffer 
:
:EndLoop
:© return number to home
:num:=expr(str)
:Disp num
:EndPrgm



There are two ways the getKey command can be used in graphics mode.

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.