#include <stdio.h>
#include <stdlib.h>
// Function to play a sound using the aplay command
void playSound(const char *soundFile) {
char command[256];
snprintf(command, sizeof(command), "aplay -q %s &", soundFile);
system(command);
}
int main() {
char key;
printf("Simple Virtual Keyboard with Sound (Linux)\n");
printf("Press 'q' to quit.\n");
while (1) {
printf("Enter a key: ");
key = getchar();
if (key == 'q') {
printf("Exiting virtual keyboard.\n");
break;
}
// Process the pressed key
switch (key) {
case 'a':
printf("Key 'a' pressed.\n");
playSound("path_to_a_sound_file.wav");
break;
case 's':
printf("Key 's' pressed.\n");
playSound("path_to_s_sound_file.wav");
break;
case 'd':
printf("Key 'd' pressed.\n");
playSound("path_to_d_sound_file.wav");
break;
case 'f':
printf("Key 'f' pressed.\n");
playSound("path_to_f_sound_file.wav");
break;
case 'g':
printf("Key 'g' pressed.\n");
playSound("path_to_g_sound_file.wav");
break;
case 'h':
printf("Key 'h' pressed.\n");
playSound("path_to_h_sound_file.wav");
break;
case 'j':
printf("Key 'j' pressed.\n");
playSound("path_to_j_sound_file.wav");
break;
case 'k':
printf("Key 'k' pressed.\n");
playSound("path_to_k_sound_file.wav");
break;
case 'l':
printf("Key 'l' pressed.\n");
playSound("path_to_l_sound_file.wav");
break;
default:
printf("Unknown key pressed.\n");
break;
}
// Clear the input buffer to avoid processing extra characters
while (getchar() != '\n');
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: