# What are the ascii numbers for shift and control?

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

• What framework do you use? – Alexandre Vaillancourt Jul 13 at 21:44
• @AlexandreVaillancourt define framework for me please – Julian Tiemann Jul 13 at 22:35
• What library/framework/engine defines event->keyval? To my knowledge, in c, to get a character, you need getchar(), which is not what is used here. – Alexandre Vaillancourt Jul 13 at 22:44

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");
}
{
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;
}

• GDK_SHIFT_MASK is an enum / POUND define macro, what is the numeric value – Julian Tiemann Jul 13 at 22:34
• i like your answer, but it does not quite answer my question – Julian Tiemann Jul 13 at 22:36
• Also, does this GDK stuff fit in a char? – Julian Tiemann Jul 13 at 22:37
• @JulianTiemann The answer to your question is that there is no ascii character that represents "shift" or "control". These are keyboard states. – Alexandre Vaillancourt Jul 13 at 22:45
• @JulianTiemann edited the answer – Ocelot Jul 13 at 22:53