ExamineKeyboard -> KeyMap

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

ExamineKeyboard -> KeyMap

Post by Kaeru Gaman »

I don't know if it was requested before...

as far I understand it, I estimate that ExamineKeyboard() requests a KeyMap
(256byte Array, quite similar to GetKeyboardState_() )
and KeyboardPushed() or KeyboardReleased() handle upon that keymap.

would it be possible to implement a more direct Handling of the KeyMap?

I'd like to access it via array,

- to handle first press of several keys more conveniant
setting a flag for each key is not that good show,
copying the "actual pressed"-Array into a "last pressed"-Array
and comparing them would greatly reduce the efford.

- to perform custom control-maps
in most games you can define your own controls.
those are best handeled via an transformation-Array
having all keys "pressed or not" in one array with greatly simplify the handling in our own games.

I estimate there already is an "actual pressed"-Array for KeyboardPushed(),
perhaps there is also a "last pressed"-Array for KeyboardReleased().
more basic access to the internal Data of the Keyboard-Lib would be a bless for Game-Programming.

(KeyboardInkey is no alternative to this)

;***********************************************
PS:
just thought a little bit more about it....
an additional KeyboardWasPushed() would do it.
maybe it's already in there, because

Code: Select all

KeyboardReleased(#Key) = Not KeyboardPushed(#Key) And KeyboardWasPushed(#Key)
KeyboardWasPushed() would at once ease handling of the First Push of any Key.
at the moment I handle it via an own Array KeyOld()

Code: Select all

  If KeyboardPushed(#PB_Key_Escape)
    If Not KeyOld(#PB_Key_Escape)  ; first press
      KeyOld(#PB_Key_Escape) = 1     ; set KeyFlag
      If MENU     ; in Menu
        EXIT = 1  ; leave Game
      Else        ; in Play
        MENU = 1  ; exit to Menu
      EndIf
    EndIf
  Else
    KeyOld(#PB_Key_Escape) = 0   ; reset KeyFlag
  EndIf
..the ControlMapping is an additional topic, I have to think more about this,
to figure out what would be the easiest solution.

;***********************************************
PPS:
I post my actual Procedure to solve the FirstPress here:

Code: Select all

Global Dim KeyOld.l(255)

Procedure.l KeyHit( Key.l )
  Protected HIT = #False
  If KeyboardPushed(Key)
    If Not KeyOld(Key)    ; first press
      KeyOld(Key) = #True  ; set KeyFlag
      HIT = #True
    EndIf
  Else
    KeyOld(Key) = #False   ; reset KeyFlag
  EndIf
  ProcedureReturn HIT
EndProcedure
works with any #PB_Key_ Constant, except #PB_Key_Any
oh... and have a nice day.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

after thinking a bit more about it...

1. an additional KeyHit() command will do a lot.

2. for Keyboard-Mapping, some commands that directly support KeyMaps would be the Hit!
...but it would be sufficent, if a direct access on the Table set up by ExamineKeyboard would be possible.

already some

Code: Select all

Key = PushedKey()
would help.

that will enable the programmer, to create a setup-menu, where the player pushes the key he want's to connect with a certain command.
the programmer gets the code of the actually pushed key back,
so he could later check his keys with a variable.

Code: Select all

; Set Command Key
If SetCommand = Down
  ComKey( Down ) = PushedKey()
EndIf

; in Game
If KeyboardPushed( ComKey( Down ) )
  ; down-action
EndIf
ComKey() is a Programmer's Array in this Example...

PS:
to complete this, some GetKeyString( #Key ) would be helpful

Code: Select all

Debug GetKeyString( #PB_Key_0 )       ; will debug "0"
Debug GetKeyString( #PB_Key_Add )     ; will debug "+"
Debug GetKeyString( #PB_Key_Escape )  ; will debug "ESC"
Debug GetKeyString( #PB_Key_F12 )     ; will debug "F12"
oh... and have a nice day.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

watching out for 4.3,
and based on an actual request in the german forums where we are sharing workarounds again,
I'd like to renew my request for a generic

Code: Select all

Key = PushedKey()
function.
oh... and have a nice day.
Post Reply