check for key presses using select case

BlitzPlus Forums/BlitzPlus Beginners Area/check for key presses using select case

SMC(Posted 2006) [#1]
I want to be able to check for keypresses using the select case method, but I'm not sure how to accomplish this. GetKey() only gives me ascii codes to work with and I would like to use scan codes for arrow keys and eventually joystick buttons. If else gets bulky after a while :(


on another note, does anyone know how to get the AutoMidHandle function to work? Plain old MidHandle works peachy, but "AutoMidHandle True" doesn't seem to do anything.


boomboom(Posted 2006) [#2]
I don't know if there is a spesific way todo this. But you could do something like:

If Keyhit(57) KeyUsed="Space"
if Keyhit(1) KeyUsed ="Esc"

Select KeyUsed
  Case "Space"
   FireFunction()
  Case "Esc"
   End
End Select
KeyUsed = "Null"


You could keep the KeyUsed if statements in an include file so they are out the way.


Jams(Posted 2006) [#3]
Select True
   Case KeyHit( 200 ): ;Do up key stuff.
   Case KeyHit( 208 ): ;Do down key stuff.
   Case KeyHit( 203 ): ;Do left key stuff.
   Case KeyHit( 205 ): ;Do right key stuff
   Case JoyHit( 1 ): ;Do joystick stuff.
End Select


:)


SMC(Posted 2006) [#4]
You rock. It's so simple too, I can't believe I didn't see it.


Nicstt(Posted 2006) [#5]
Sample of code im using - I assigned the letters and symbols I wanted to use in a type.

I had checks for cursor and deletion, with a check if shift was held or not.

May not be best way, but it works well for me.

Points of interest KeyHit and KeyDown rest is my code for handling input and edditing.


	For lettx.text_letter = Each text_letter
	If KeyDown(42) = False And KeyDown(54) = False
		If (KeyHit(lettx\scancode) = True And Len(lettx\symbol$) = 1 And StringWidth(curs_count_len$) <= 261)
			name2$ = (Left$(name_bar_text$,curs_count))
			name1$ = (Mid$ (name_bar_text$,curs_count + 1,(Len(name_bar_text$) - Len(name2$) ) ) )
			name_bar_text$ = name2$ + lettx\symbol$ + name1$
			curs_count = curs_count + 1
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(14) = True); Backspace
			name2$ = (Left$(name_bar_text$,curs_count - 1))
			name1$ = (Mid$ (name_bar_text$,curs_count + 1,(Len(name_bar_text$) - (Len(name2$)+1) ) ) )
			name_bar_text$ = name2$ + name1$
			curs_count = curs_count - 1 
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(203) = True)
			curs_count = curs_count - 1
			If curs_count < 0 Then curs_count = 0
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(205) = True)
			curs_count = curs_count + 1
			If curs_count > Len(name_bar_text$) Then curs_count = Len(name_bar_text$)
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(199) = True)
			curs_count = 0
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(207) = True)
			curs_count = Len(name_bar_text$)
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(28) = True) Or (KeyHit(156) = True)
			; ********************** code saves **************************
			reset = True
			ML = 0 : FlushMouse : FlushKeys : Goto codetosave
		EndIf
	ElseIf KeyDown(42) = True Or KeyDown(54) = True
		If (KeyHit(lettx\scancode) = True And Len(lettx\caps_symbol$) = 1 And StringWidth(curs_count_len$) <= 261)
			name2$ = (Left$(name_bar_text$,curs_count))
			name1$ = (Mid$ (name_bar_text$,curs_count + 1,(Len(name_bar_text$) - Len(name2$) ) ) )
			name_bar_text$ = name2$ + lettx\caps_symbol$ + name1$
			curs_count = curs_count + 1
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(14) = True); Backspace
			name2$ = (Left$(name_bar_text$,curs_count - 1))
			name1$ = (Mid$ (name_bar_text$,curs_count + 1,(Len(name_bar_text$) - (Len(name2$)+1) ) ) )
			name_bar_text$ = name2$ + name1$
			curs_count = curs_count - 1 
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(203) = True)
			curs_count = 0
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(205) = True)
			curs_count = Len(name_bar_text$)
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(199) = True)
			curs_count = 0
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(207) = True)
			curs_count = Len(name_bar_text$)
			curs_count_len$ = (Left$(name_bar_text$,curs_count))
		ElseIf (KeyHit(28) = True) Or (KeyHit(156) = True)
			; ********************** code saves **************************
			reset = True
			ML = 0 : FlushMouse : FlushKeys : Goto codetosave
		EndIf
	EndIf
Next