Skip to content

Implement key presses #1

@mratsim

Description

@mratsim

Currently there is no keypress support.

The following loop must be modified:

chirp8/src/chirp8.nim

Lines 34 to 44 in ba98bdb

while gameState.running:
while sdl2.pollEvent(gameState.event):
case gameState.event.kind:
of QuitEvent:
gameState.running = false
break
of KeyDown:
gameState.running = false
break
else:
break

KeyDOWN matches pressing
KeyUp matches release

So something like that can be done

 while gameState.running: 
   while sdl2.pollEvent(gameState.event): 
     case gameState.event.kind: 
     of QuitEvent: 
       gameState.running = false 
       break 
     of KeyDown: 
       case event.key.keysym.sym:
       of K_KP0: foo(key0)
       of K_KP1: foo(key1)
       ...
     else: 
       break 

Keycodes are available here: https://github.com/nim-lang/sdl2/blob/master/src/sdl2/private/keycodes.nim

A new "key" array should be added to store the key states (up or down)

Layout

The original key layout is this:

2018-03-31_11-28-02

with 2-4-6-8 corresponding to up left right down.

Ideally Chirp-8 should read mapping from a .cfg to so that people can customize their keyboard mapping:

  • laptops without a keypad
  • non-QWERTY keyboard
  • ...

cc @Vindaar

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions