Pridana detekce keypressu
authorTomas Mudrunka <tomas@mudrunka.cz>
Thu, 16 Jul 2020 13:54:49 +0000 (15:54 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Thu, 16 Jul 2020 13:54:49 +0000 (15:54 +0200)
c/SDL2_putpixel_click/main.c

index 1acfdb25e67fe2e2cb4f15edce84c233f71ff458..8032752b1a90e8ea21871982cf8b4e3000fca75b 100644 (file)
@@ -1,5 +1,6 @@
 //gcc -Wextra -pedantic-errors -o main.out main.c -lSDL2
 
+#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -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);
This page took 0.161636 seconds and 4 git commands to generate.