# How do I get the keyCode?

**URL:** <https://discourse.processing.org/t/how-do-i-get-the-keycode/794>\
**Category:** Coding Questions\
**Created:** [June 8, 2018, 3:47am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794 "2018-06-08T03:47:42Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [June 8, 2018, 3:47am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/1 "2018-06-08T03:47:43Z")

</div>

I want to make a KeyHandler class to make it so I can press multiple keys, but I don’t know how to get the ASCII integer value for every key, how do I do this?

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 8, 2018, 3:58am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/2 "2018-06-08T03:58:41Z")

</div>

Why do you need the ascii code? What are some example keys that you’re trying to use?

---

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [June 8, 2018, 4:18am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/3 "2018-06-08T04:18:30Z")

</div>

I need to get if any key on the keyboard is pressed.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 8, 2018, 4:40am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/4 "2018-06-08T04:40:51Z")

</div>

I’m not sure I understand what you’re asking- doesn’t the `keyCode` variable already give you that?

---

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [June 8, 2018, 4:45am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/5 "2018-06-08T04:45:18Z")

</div>

It only gives coded keys like shift, control, ect.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 8, 2018, 4:48am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/6 "2018-06-08T04:48:27Z")

</div>

Have you tested that theory? The `keyCode` variable prints out ascii values for all of the keys on my keyboard.

---

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [June 8, 2018, 4:49am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/7 "2018-06-08T04:49:35Z")

</div>

Yup. I have. Every other key prints out 0.

---

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [June 8, 2018, 4:49am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/8 "2018-06-08T04:49:59Z")

</div>

This is also for that 3D engine!

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 8, 2018, 5:01am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/9 "2018-06-08T05:01:48Z")

</div>

Hmm, interesting. The `keyCode` works fine for me on Windows. Maybe it’s a platform-specific thing.

The `key` variable contains the character that was typed. You can probably just cast to `int` to get the ascii code:

```auto
println( (int) key );

```

---

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [June 8, 2018, 5:03am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/10 "2018-06-08T05:03:32Z")

</div>

I’ll try that, but, I AM using Windows! Hmmm…

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 8, 2018, 5:05am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/11 "2018-06-08T05:05:53Z")

</div>

Try this sketch:

```auto
void draw(){}

void keyPressed(){
 println("key: " + key);
 println("int key: " + (int) key);
 println("keyCode: " + keyCode);
 println();
}

```

For me, this prints out reasonable values for every key on my keyboard.

---

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [June 8, 2018, 5:42am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/12 "2018-06-08T05:42:59Z")

</div>

It works! Thanks a lot!!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 8, 2018, 6:23am UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/13 "2018-06-08T06:23:56Z")

</div>

[http://Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G)

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 8, 2018, 4:14pm UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/14 "2018-06-08T16:14:55Z")

</div>

@GoToLoop Can you please include an explanation when you post links?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 8, 2018, 4:19pm UTC](https://discourse.processing.org/t/how-do-i-get-the-keycode/794/15 "2018-06-08T16:19:11Z")

</div>

Haha plus 1 from me for that post
