I am writing a C program to control an ARDrone, and would like the drone to move as long as a key is pressed down, and when the key is no longer pressed down I want it to stop moving. I attached both a key_press_event and key_release_event to the window I created, and here is the callback function:
gint key_press_cb(GtkWidget *widget,
GdkEventKey *kevent,
gpointer data)
{
unsigned int key;
int res;
/* While a key is pressed the drone moves,
* when the key is released it is put back into hover mode */
if(kevent->type == GDK_KEY_RELEASE) {
// Hover mode
printf("--- Hover Mode ---\n");
ardrone_at_set_progress_cmd(0, 0, 0, 0, 0);
//res = keyboard_update(BACKSPACE);
} else if(kevent->type == GDK_KEY_PRESS) {
key = kevent->keyval;
g_message("Key pressed: %c [%d]", key, key);
res = keyboard_update(key);
}
return TRUE;
}
I will get a key release event if I hold down the key for a short period of time, but when holding it down for 2+ seconds I will not see the key release event. I was thinking it could be because I am constantly receiving key_press_events while holding down a key; is there any way to disable that repeat?
I found the problem if anyone was wondering. In my
keyboard_update()function I was callingg_signal_emit_by_name(G_OBJECT(/*button*/), "activate", NULL)to have the button pressed down when the user pressed the corresponding key. Once I removed this feature the key release event was being recognized again. Not sure why this happens but I can live without this feature for now.