Skip to content

Instantly share code, notes, and snippets.

@bostrt
Last active July 6, 2024 21:22
Show Gist options
  • Save bostrt/8cbfcea6c6dbd6d3c50669e84b9863ca to your computer and use it in GitHub Desktop.
Save bostrt/8cbfcea6c6dbd6d3c50669e84b9863ca to your computer and use it in GitHub Desktop.
SDL Key Code Miyoo Mini+ Button
SDL_KEYDOWN: Keycode: Up (1073741906) Scancode: Up (82) UP ARROW
SDL_KEYUP: Keycode: Up (1073741906) Scancode: Up (82)
SDL_KEYDOWN: Keycode: Right (1073741903) Scancode: Right (79) RIGHT ARROW
SDL_KEYUP: Keycode: Right (1073741903) Scancode: Right (79)
SDL_KEYDOWN: Keycode: Down (1073741905) Scancode: Down (81) DOWN ARROW
SDL_KEYUP: Keycode: Down (1073741905) Scancode: Down (81)
SDL_KEYDOWN: Keycode: Left (1073741904) Scancode: Left (80) LEFT ARROW
SDL_KEYUP: Keycode: Left (1073741904) Scancode: Left (80)
SDL_KEYDOWN: Keycode: Left Shift (1073742049) Scancode: Left Shift (225) X
SDL_KEYUP: Keycode: Left Shift (1073742049) Scancode: Left Shift (225)
SDL_KEYDOWN: Keycode: Left Ctrl (1073742048) Scancode: Left Ctrl (224) A
SDL_KEYUP: Keycode: Left Ctrl (1073742048) Scancode: Left Ctrl (224)
SDL_KEYDOWN: Keycode: Left Alt (1073742050) Scancode: Left Alt (226) B
SDL_KEYUP: Keycode: Left Alt (1073742050) Scancode: Left Alt (226)
SDL_KEYDOWN: Keycode: Space (32) Scancode: Space (44) Y
SDL_KEYUP: Keycode: Space (32) Scancode: Space (44)
SDL_KEYDOWN: Keycode: Return (13) Scancode: Return (40) START
SDL_KEYUP: Keycode: Return (13) Scancode: Return (40)
SDL_KEYDOWN: Keycode: Escape (27) Scancode: Escape (41) SELECT
SDL_KEYUP: Keycode: Escape (27) Scancode: Escape (41)
SDL_KEYDOWN: Keycode: Home (1073741898) Scancode: Home (74) MIDDLE BUTTON
SDL_KEYUP: Keycode: Home (1073741898) Scancode: Home (74)
SDL_KEYDOWN: Keycode: Tab (9) Scancode: Tab (43) L
SDL_KEYUP: Keycode: Tab (9) Scancode: Tab (43)
SDL_KEYDOWN: Keycode: PageDown (1073741902) Scancode: PageDown (78) L2
SDL_KEYUP: Keycode: PageDown (1073741902) Scancode: PageDown (78)
SDL_KEYDOWN: Keycode: PageUp (1073741899) Scancode: PageUp (75) R2
SDL_KEYUP: Keycode: PageUp (1073741899) Scancode: PageUp (75)
SDL_KEYDOWN: Keycode: Backspace (8) Scancode: Backspace (42) R
SDL_KEYUP: Keycode: Backspace (8) Scancode: Backspace (42)
/*
* SDL2 mousebutton test
*
* build with:
* $ gcc $(sdl2-config --cflags) -o sdl2test sdl2test.c $(sdl2-config --libs)
*/
#include <stdio.h>
#include <SDL.h>
#include <errno.h>
void eventloop(FILE* outfile) {
while(1) {
SDL_Event ev;
fflush(outfile);
if(SDL_PollEvent(&ev) == 0) {
//printf(".\n");
SDL_Delay(1);
continue;
}
switch(ev.type) {
case SDL_QUIT:
fprintf(outfile, "Received SDL_QUIT - bye!\n");
return;
case SDL_MOUSEBUTTONUP:
fprintf(outfile, "SDL_MOUSEBUTTONUP, button %d clicks %d\n", ev.button.button, (int)ev.button.clicks);
break;
case SDL_MOUSEBUTTONDOWN:
fprintf(outfile, "SDL_MOUSEBUTTONDOWN, button %d clicks %d\n", ev.button.button, (int)ev.button.clicks);
break;
case SDL_KEYUP:
case SDL_KEYDOWN:
if(ev.type == SDL_KEYUP)
fprintf(outfile, "SDL_KEYUP: ");
else
fprintf(outfile, "SDL_KEYDOWN: ");
fprintf(outfile, "Keycode: %s (%d) Scancode: %s (%d)\n",
SDL_GetKeyName(ev.key.keysym.sym), ev.key.keysym.sym,
SDL_GetScancodeName(ev.key.keysym.scancode),
ev.key.keysym.scancode);
if(ev.key.keysym.sym == SDLK_q) {
fprintf(outfile, "You pressed Q - bye!\n");
return;
}
break;
case SDL_MOUSEWHEEL:
fprintf(outfile, "MouseWheel: x: %d, y: %d\n", ev.wheel.x, ev.wheel.y);
break;
case SDL_TEXTINPUT:
fprintf(outfile, "SDL_TEXTINPUT: %s\n", ev.text.text ? ev.text.text : "<NULL>");
break;
case SDL_JOYBUTTONDOWN:
fprintf(outfile, "SDL_JOYBUTTONDOWN dev %d button %d state %d\n",
(int)ev.jbutton.which, (int)ev.jbutton.button, (int)ev.jbutton.state);
break;
case SDL_JOYBUTTONUP:
fprintf(outfile, "SDL_JOYBUTTONUP dev %d button %d state %d\n",
(int)ev.jbutton.which, (int)ev.jbutton.button, (int)ev.jbutton.state);
break;
case SDL_MOUSEMOTION:
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION:
break; // ignore
case SDL_WINDOWEVENT:
break;
default:
// fprintf(outfile, "SDL_Event of type: 0x%x received\n", ev.type);
break;
}
}
}
int main(int argc, char** argv) {
//SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
SDL_Init(SDL_INIT_EVERYTHING);
//SDL_StartTextInput();
SDL_Joystick* gGameController = NULL;
SDL_Window* win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
//SDL_SetRelativeMouseMode(1);
//SDL_SetWindowGrab(win, 1);
SDL_SetWindowTitle(win, "SDL input test");
// fill the window with black, so it shows something deterministic
// (and works with wayland)
{
SDL_Surface *s = SDL_GetWindowSurface(win);
Uint32 black = SDL_MapRGB(s->format, 0, 0, 0);
SDL_FillRect(s, NULL, black);
SDL_UpdateWindowSurface(win);
}
if( SDL_NumJoysticks() < 1 )
{
printf( "Warning: No joysticks connected!\n" );
}
else
{
//Load joystick
gGameController = SDL_JoystickOpen( 0 );
if( gGameController == NULL )
{
printf( "Warning: Unable to open game controller! SDL Error: %s\n", SDL_GetError() );
}
}
#ifdef _WIN32
// output debug prints to file on windows
const char* filename = "sdl2_test_out.txt";
#else
// output debug prints to stdout on other OS
const char* filename = "-";
#endif
FILE* output = NULL;
if(argc > 1) {
filename = argv[1];
}
if(strcmp(filename, "-") == 0)
output = stdout;
else
output = fopen(filename, "w");
if(!output) {
fprintf(stderr, "Couldn't create debug output file!\n");
exit(1);
}
if(gGameController != NULL) {
fprintf(output, "Going with game controller\n");
} else {
fprintf(output, "No game controller\n");
}
eventloop(output);
if(strcmp(filename, "-") != 0)
fclose(output);
SDL_JoystickClose( gGameController );
gGameController = NULL;
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment