From: Tomas Mudrunka Date: Thu, 16 Jul 2020 13:54:49 +0000 (+0200) Subject: Pridana detekce keypressu X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=5a018b175808ccf154279254a17753e9d9824a61;p=mirrors%2FPrograms.git Pridana detekce keypressu --- diff --git a/c/SDL2_putpixel_click/main.c b/c/SDL2_putpixel_click/main.c index 1acfdb2..8032752 100644 --- a/c/SDL2_putpixel_click/main.c +++ b/c/SDL2_putpixel_click/main.c @@ -1,5 +1,6 @@ //gcc -Wextra -pedantic-errors -o main.out main.c -lSDL2 +#include #include #include @@ -35,18 +36,29 @@ int main(void) { case SDL_QUIT: running = 0; break; + case SDL_KEYDOWN: + //case SDL_KEYUP: + printf("Key: %d\t%d\t%d\n", event.key.keysym.scancode, event.key.keysym.sym, event.key.keysym.mod ); + break; case SDL_MOUSEBUTTONDOWN: //do whatever you want to do after a mouse button was pressed, // e.g.: //if(event.button.button == SDL_BUTTON_LEFT) { - SDL_GetMouseState(&mouseX, &mouseY); - printf("Click %d, %d, %d\n", mouseX, mouseY, event.button.button); - SDL_RenderDrawPoint(renderer, mouseX, mouseY); - SDL_RenderPresent(renderer); + while(event.type != SDL_MOUSEBUTTONUP) { + SDL_GetMouseState(&mouseX, &mouseY); + SDL_RenderDrawPoint(renderer, mouseX, mouseY); + SDL_RenderDrawPoint(renderer, mouseX, mouseY+1); + SDL_RenderDrawPoint(renderer, mouseX+1, mouseY); + SDL_RenderDrawPoint(renderer, mouseX+1, mouseY+1); + SDL_RenderPresent(renderer); + SDL_PollEvent(&event); + } + printf("Click: %d\t%d\t%d\n", mouseX, mouseY, event.button.button); //} break; } } + usleep(10000); } SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window);