# GLFW\_KEY\_W not working (not compiling

**URL:** <https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210>\
**Category:** support\
**Created:** [November 17, 2018, 7:00pm UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210 "2018-11-17T19:00:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![welton](https://avatars.discourse-cdn.com/v4/letter/w/4bbf92/32.png) [@welton](https://discourse.glfw.org/u/welton)\
**Post date:** [November 17, 2018, 7:00pm UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/1 "2018-11-17T19:00:50Z")

</div>

Hello, I recently added this code:

` case GLFW_KEY_W:
         y_location+=5;
         break;
      case GLFW_KEY_S:
         y_location-=5;
         break;
      case GLFW_KEY_A:
         x_location-=5;
         break;
      case GLFW_KEY_87:
         x_location+=5;
         break;`

Unfortunately, it does not compile. It keeps saying [quote]In function ‘void handleKeypress(int, int)’😑  
|23|error: ‘GLFW\_KEY\_W’ was not declared in this scope|  
|26|error: ‘GLFW\_KEY\_S’ was not declared in this scope|  
|29|error: ‘GLFW\_KEY\_A’ was not declared in this scope|  
|32|error: ‘GLFW\_KEY\_D’ was not declared in this scope|  
[/quote]

So, what I am doing wrong this time? Thanks for the effort.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 17, 2018, 7:23pm UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/2 "2018-11-17T19:23:03Z")

</div>

It looks like you haven’t included the glfw header file.

---

<div class="post-metadata">

**Author:** ![welton](https://avatars.discourse-cdn.com/v4/letter/w/4bbf92/32.png) [@welton](https://discourse.glfw.org/u/welton)\
**Post date:** [November 20, 2018, 9:12pm UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/3 "2018-11-20T21:12:17Z")

</div>

But it works with a lot of other keys. And the glfw header is included.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 21, 2018, 10:15am UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/4 "2018-11-21T10:15:24Z")

</div>

It’s difficult to help without seeing more of the code, however there is at least one error in what you’ve put above as there is no `GLFW_KEY_87`, I think you mean `GLFW_KEY_W` which has number 87. Note that for the printable keys you can also use their upper case character representation, such as`'W'` in this case.

---

<div class="post-metadata">

**Author:** ![welton](https://avatars.discourse-cdn.com/v4/letter/w/4bbf92/32.png) [@welton](https://discourse.glfw.org/u/welton)\
**Post date:** [November 22, 2018, 8:45pm UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/5 "2018-11-22T20:45:10Z")

</div>

Well, let’s see if this code might be of some help:

```c
void GLFWCALL handleKeypress (int key, int press) {
   switch (key) {
      case GLFW_KEY_ESC:
         exit(1);
         break;
      case GLFW_KEY_RIGHT:
         rotate_y+=5;
         break;
      case GLFW_KEY_LEFT:
         rotate_y-=5;
         break;
      case GLFW_KEY_UP:
         rotate_x+=5;
         break;
      case GLFW_KEY_DOWN:
         rotate_x-=5;
         break;
      case GLFW_KEY_W:
         y_location+=5;
         break;
      case GLFW_KEY_S:
         y_location-=5;
         break;
      case GLFW_KEY_A:
         x_location-=5;
         break;
      case GLFW_KEY_D:
         x_location+=5;
         break;
    }
}

```

Such code will simply not compile unless I comment out everything between

> [@](#):
>
> case GLFW\_KEY\_W:

> [@](#):
>
> case GLFW\_KEY\_D:

with messages such as

> [@](#):
>
> /media/34GB/demos/Ogl/OpenGL.cpp|23|error: ‘GLFW\_KEY\_W’ was not declared in this scope|

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 23, 2018, 10:51am UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/6 "2018-11-23T10:51:06Z")

</div>

This helps a lot actually, since you are using `GLFW_KEY_ESC` which only exists in GLFW 2, not GLFW 3 (GLFW 3 has `GLFW_KEY_ESCAPE`).

So it looks like you are using GLFW 2 not GLFW 3. GLFW 2 does not have the 0-9 and A-Z keys defined using GLFW\_KEY\_? so you need to using `'W'`, `'S'`, `'A'`, `'D'` or switch to GLFW 3. If you switch do read [http://www.glfw.org/docs/latest/moving\_guide.html#moving\_keys](http://www.glfw.org/docs/latest/moving_guide.html#moving_keys).

---

<div class="post-metadata">

**Author:** ![welton](https://avatars.discourse-cdn.com/v4/letter/w/4bbf92/32.png) [@welton](https://discourse.glfw.org/u/welton)\
**Post date:** [November 23, 2018, 8:37pm UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/7 "2018-11-23T20:37:33Z")

</div>

So do I have to know the corresponding ascii numbers of these keys? I ask that because the “key” bariable is an int. Or shall I change it to a char and use [quote]case ‘w’[/quote]

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 23, 2018, 11:00pm UTC](https://discourse.glfw.org/t/glfw-key-w-not-working-not-compiling/1210/8 "2018-11-23T23:00:50Z")

</div>

You should be able to change the code to:

```auto
case 'W':
y_location+=5;
break;
case 'S':
y_location-=5;
break;
case 'A':
x_location-=5;
break;
case 'D':
x_location+=5;
break;

```

This works because char is an integer type, and can be promoted to int without loss (see [https://wiki.sei.cmu.edu/confluence/display/c/INT02-C.+Understand+integer+conversion+rules](https://wiki.sei.cmu.edu/confluence/display/c/INT02-C.+Understand+integer+conversion+rules)).
