How can I disable a key from being used?
Blitz3D Forums/Blitz3D Beginners Area/How can I disable a key from being used?
| ||
| How can I disable a key from being used? Here is what I am trying to do
If KeyHit(57)
DisableKey(57)
EndIf
How? |
| ||
FlushKeys() [Edit] Local State_Key% = False Local Key_Space% = 57 If KeyHit(Key_Space%) = True And State_Key% = False Print "Key 57 Hit" State_Key% = true End If Last edited 2012 |
| ||
| With computer languages you can only affect things inside the computer, you have no change to manipulate the user. So... How can I disable a key from being used? ...the anser is No way! ;-) But, why not simply ingnore it? In Blitz nothing happens with keys before you did not code it. So, if you will not allow SPACE to be added to a string, do not add it: Local Name$
Repeat
Key=GetKey()
If Key>0 then
Name=Name+ Chr(Key)
Endif
Print Name
Until KeyHit(1)becomes: Local Name$
Repeat
Key=Allowed( GetKey() )
If Key>0 then
Name=Name+ Chr(Key)
Endif
Print Name
Until KeyHit(1)
Function Allowed%(Key%)
; GetKey works with ASCII not Scancodes!
If Key= 0 Then Return 0
If Key= 32 Then Return 0
; more lines here f.e. forbid all numbers:
If (Key>47) and (Key< 58) Then Return 0
Return Key
End FunctionThis also could be a possibility to switch key permission ON or OFF during the game: Dim CancelKey%(255)
CancelKey(57)=TRUE
For i%=48 to 57
CancelKey(i)=TRUE
Next
Time=Millisecs()+10*1000
Repeat
If Allowed(57) Then
; do something in the game
Endif
; sample: allow SPACE after 10 seconds:
If Time<Millisecs()
CancelKey(57)=FALSE
Endif
Until KeyHit(1)
Function Allowed%(KeyNr%)
KeyH%=KeyHit(KeyNr)
If CancelKey(KeyNr)=TRUE then Return 0
Return KeyH
End Function |