Event functions
Functions for receiving keyboard-strokes, mouse-clicks and -moves or gamecontroller-/joystick-actions.
(For simplifying key-handling with the system-menu
see also Simplifying key-handling with System-menu (and networking))
- Structures and Enumerations
- Handling events
- VG3_inputevent_update()
Retrieve events of input-devices. - VG3_discard_input()
Discard pressed keys on keyboard and gamecontroller and set them to non-pressed. - Keyboard
- VG3_key_ispressed()
Check if a specific key is pressed. - VG3_key_getpressed()
Return which key is pressed, if only one key is pressed (e.g. for defining it for an action). - VG3_key_num2name()
Return the name (string) of a key-definition. - VG3_key_name2num()
Return the key-definition (integer) of a key-name. - Mouse
- VG3_mouserelease()
Define keyboard-key for releasing mouse from the game-window (default key is delete-key). - VG3_mouse_ispressed()
Return which mouse-buttons are pressed. - VG3_mouse_position()
Return mouse-position. - Gamecontroller/Joystick
- VG3_gamecontroller_getall()
Return number of found gamecontrollers and their id-numbers. - VG3_gamecontroller_getinfo()
Return information of a gamecontroller. - VG3_gamecontroller_ispressed()
Check if a specific key or axis is pressed. - VG3_gamecontroller_getpressed()
Return which key or axis is pressed, if only one key or axis is pressed (e.g. for defining it for an action). - VG3_gamecontroller_num2name()
Return the name (string) of a key- or axis-definition. - VG3_gamecontroller_name2num()
Return the key- or axis-definition (integer) of a key- or axis-name.
Example
/* print infos of gamecontrollers and joysticks * print exclusively pressed keyboard-keys, until return-key is pressed */ struct vg3_window *wstruct; /* open window */ wstruct = VG3_window_new(argv[0], VGAG3_VGAVERSION_LOW, VGAG3_WINSCALE_NOSCALE); if (wstruct == NULL) { fprintf(stderr, "%s\n", VG3_error()); exit(1); } /* print infos of all found gamecontrollers and joysticks */ { int *rjid, idx, jid; struct vg3_gamecontroller gcs; VG3_gamecontroller_getall(wstruct, &rjid); for (idx = 1; idx <= rjid[0]; idx++) { /* for each device */ jid = rjid[idx]; VG3_gamecontroller_getinfo(wstruct, jid, &gcs); if (gcs.is_gamecontroller) { printf("Gamecontroller %d [joystick-ID=%d]: \"%s\"\n", idx, gcs.jid, gcs.name); } else { printf("Joystick %d [joystick-ID=%d], buttons/axes=%d: \"%s\"\n", idx, gcs.jid, gcs.joy_num_input, gcs.name); } } /* free array */ free(rjid); } /* print exclusively pressed keyboard-keys, until return-key is pressed */ printf("\nPress keys, quit with return-key\n"); { int kbidx; /* throw away pending events */ VG3_discard_input(wstruct); /* game-loop */ for (;;) { /* retrieve new events, exit if got request for closing the window */ if (VG3_inputevent_update(wstruct) > 0) { break; } /* check if return-key is pressed for exiting */ if (VG3_key_ispressed(wstruct, VGAG3_KEY_ENTER, VGAG3_IS_NEW_PRESSED)) { break; } /* print out exclusively pressed keys */ kbidx = VG3_key_getpressed(wstruct); if (kbidx != VGAG3_KEY_NOKEY) { printf("%s pressed\n", VG3_key_num2name(wstruct, kbidx)); } /* wait up to 50 msec */ VG3_wait_time(50); } /* again throw away pending events */ VG3_discard_input(wstruct); } /* close window */ VG3_window_free(wstruct);