-2

I is trying to makey makey a program that will detect when certain keys are pushed. My only problem is that I dont know the nombers that corrospond to the shift key and control keys. I am writing this code for a game. Here are teh codes:

switch(event->keyval) {
    case ?:
        printf("Shift key was pressed");
    break;
    case ??:
        printf("Control key waas pressed");
    break;
}

What can replace ""?"" and ""??""

Also, if possible, my answer SHOULD be able to fit in a char type

1 Answers1

1

To get state of the shift and control buttons in GTK, you need to apply bitwise AND to the event state.

if(event->state & GDK_SHIFT_MASK)
{
    printf("Shift key was pressed");
}
else if(event->state & GDK_CONTROL_MASK)
{
    printf("Control key was pressed");
}

Alternatively, you can use macros (or their values, but please don't) defined in gdkkeysyms.h

#define GDK_KEY_Shift_L 0xffe1

#define GDK_KEY_Shift_R 0xffe2

#define GDK_KEY_Control_L 0xffe3

#define GDK_KEY_Control_R 0xffe4

switch(event->keyval) {
    case GDK_KEY_Shift_L:
        printf("Left shift key was pressed");
    break;
    case GDK_KEY_Shift_R:
        printf("Right shift key was pressed");
    break;
    case GDK_KEY_Control_L:
        printf("Left control key was pressed");
    break;
    case GDK_KEY_Control_R:
        printf("Right control key was pressed");
    break;
}
Ocelot
  • 1,433
  • 1
  • 12
  • 21