-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_hook.c
30 lines (25 loc) · 960 Bytes
/
key_hook.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "mlx/mlx.h"
#include <stdio.h>
#include <stdlib.h>
// Função simples que printa a tecla apertada no terminal, e fecha o programa ao apertar P
//>>Atenção ao protótipo da função, int func(int), onde o primeiro argumento é a tecla pressionada, e o segundo é o que você definiu na mlx_key_hook(linha 28),
//caso tenha definido, se não definir nenhum, ela recebe apenas o primeiro argumento (print_key(int key))<<<
int print_key(int key, char *str)
{
//Printa o argumento passado na mlx_key_hook
printf("%s\n", str);
printf("%c\n", key);
if (key == 'p')
exit(1);
}
int main(void)
{
void *mlx;
void *win;
mlx = mlx_init();
win = mlx_new_window(mlx, 100, 100, "teste");
//Função da lib para reagir à inputs do teclado, mlx_hook também tem várias opções uteis, mas é mais complexa
//O terceiro argumento é opcional, caso não acrescente nenhum, defina como (void *)0
mlx_key_hook(win, print_key, "Oi");
mlx_loop(mlx);
}