Skip to content

Instantly share code, notes, and snippets.

@croepha
Last active February 1, 2018 07:06
Show Gist options
  • Save croepha/ace62549bb0a92ff3fc59d51bce718bf to your computer and use it in GitHub Desktop.
Save croepha/ace62549bb0a92ff3fc59d51bce718bf to your computer and use it in GitHub Desktop.
sdk_kb_mash_test.cpp
#include <stdio.h>
#include <assert.h>
//#include <SDL.h>
#include <SDL2/SDL.h>
bool keys_hit[512] = {};
SDL_Keycode __small_keysym_to_sdl_keysym(int smks) {
SDL_Keycode ret = 0;
if (smks >= 256) {
ret = 0x40000000;
}
ret = ret | (smks &0xff);
return ret;
}
int __sdl_keysym_to_small_keysym(SDL_Keycode sdl_k) {
int ret = 0xff & sdl_k;
if (0x40000000 & sdl_k) ret += 256;
assert(ret >=0);
assert(ret < 512);
assert(sdl_k == __small_keysym_to_sdl_keysym(ret));
keys_hit[ret] = true;
int hit_count = 0;
bool in_used_range = false;
for (int i=0;i<512;i++) {
if(keys_hit[i]) {
if (!in_used_range) {
printf("%d - ", i);
in_used_range = true;
}
hit_count++;
} else {
if (in_used_range) {
printf("%d, ", i-1);
in_used_range = false;
}
}
}
printf("\n");
printf("keys hit_count %d\n", hit_count);
return ret;
};
int main () {
auto r1 = SDL_Init(SDL_INIT_VIDEO);
assert(!r1);
auto window = SDL_CreateWindow("BLOOP", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
1280, 720, SDL_WINDOW_RESIZABLE);
assert(window);
bool done=false;
while(!done) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN: {
auto k = event.key.keysym.sym;
static unsigned int ALL_KEY_MASK = 0;
ALL_KEY_MASK = ALL_KEY_MASK | k;
printf("ALL_KEY_MASK:%x small:%d\n", ALL_KEY_MASK, __sdl_keysym_to_small_keysym(k));
} break;
case SDL_QUIT: {
done = true;
} break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment