# \[C++\] Keyboard Codes

**URL:** <https://forum.kirupa.com/t/c-keyboard-codes/252445>\
**Category:** programming\
**Created:** [February 20, 2008, 7:51am UTC](https://forum.kirupa.com/t/c-keyboard-codes/252445 "2008-02-20T07:51:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [February 20, 2008, 7:51am UTC](https://forum.kirupa.com/t/c-keyboard-codes/252445/1 "2008-02-20T07:51:13Z")

</div>

I’m using the OpenGL/Glut library. In the handleKeyPress function, I attempted to display the key that was pressed. To my surprise, the cout is only triggered when the exit key is pressed. So how can I find the number that corresponds to the key? Anyone have a chart?

```auto

void handleKeyPress(unsigned char key, int mouseX, int mouseY) {
	cout << "key: " << key << endl;

	switch (key) {
		// escape
		case 27:
			exit(0);
			break;
	}
}

```
