Checking for KeyHit() and other stuff...

Blitz3D Forums/Blitz3D Programming/Checking for KeyHit() and other stuff...

hollifd(Posted March) [#1]
I am trying to check for a keyhit AND other criteria like:

If keyhit(30) and ItemToMove$ = "part" then
  ;Do some stuff
end if

If keyhit(30) and ItemToMove$ = "LTool" then
  ;Do some stuff
end if

If keyhit(30) and ItemToMove$ = "UTool" then
  ;Do some stuff
end if


It seems to not recognize each of these if statements and the code below each If statement does not execute. Should this work in Blitz? Is there a better way?

Thanks,
David


steve_ancell(Posted March) [#2]
There ya go!, the regular KeyHit function is a pain in the chad. KeyDown works far better and can act as a KeyHit when used the proper way. You simply check if the key is still held down, so you only get a hit when it's let go of and then re-pressed.

Stick the Dim/array somewhere before the function and then use KeyHit_2 in the same way as the regular KeyHit function. ;)

The same applies to MouseHit and JoyHit, just make the relevant arrays and functions in the same way as this.




Matty(Posted March) [#3]
KeyHit/MouseHit gets cleared after each call.

Store the result of Mousehit/Keyhit in a variable and test the variable.

Each time you call Keyhit it counts the number of times it has been pressed since the last call to it.

So if you include it in successive if statements then it will be zero after the first time unless you happen to hit the key really, really, really quickly between two lines of code! (highly unlikely ever)


Midimaster(Posted March) [#4]
If keyhit(30)
    Select ItemToMove
        Case "part"
            ;Do some stuff
        Case "LTool"
            ;Do some stuff
        Case "UTool"
            ;Do some stuff
    End Select
Endif



hollifd(Posted March) [#5]
Thanks guys! It works much better now.