# How do I get the key state of the Apple key?

**URL:** <https://discourse.libsdl.org/t/how-do-i-get-the-key-state-of-the-apple-key/20683>\
**Category:** SDL Development\
**Created:** [May 15, 2014, 6:01am UTC](https://discourse.libsdl.org/t/how-do-i-get-the-key-state-of-the-apple-key/20683 "2014-05-15T06:01:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Explodey](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/e/ecb155/32.png) [@Explodey](https://discourse.libsdl.org/u/Explodey)\
**Post date:** [May 15, 2014, 6:01am UTC](https://discourse.libsdl.org/t/how-do-i-get-the-key-state-of-the-apple-key/20683/1 "2014-05-15T06:01:35Z")

</div>

I’m using SDL\_GetKeyState() in a program to get the states of the modifier keys (shift, control, option, and command). I have no problem getting the state of shift, control, and option (using SDLK\_LSHIFT, SDLK\_LCTRL, and SDLK\_LALT), but I don’t know what to use to get the state of the command key, i.e., the Apple Key. I found one site that says to use SDLK\_LGUI, but SDL doesn’t seem to recognize that on my setup (it says: ‘SDLK\_LGUI’ was not declared in this scope).

I’m using SDL1. My IDE is Xcode 3.2.6, and I’m on an iMac, running OSX 10.6. I should also probably mention that I’m still pretty new to SDL and C++, so I might have trouble getting my head around some of the more advanced stuff!

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [May 15, 2014, 9:07am UTC](https://discourse.libsdl.org/t/how-do-i-get-the-key-state-of-the-apple-key/20683/2 "2014-05-15T09:07:55Z")

</div>

> state of the command key, i.e., the Apple Key. I found one site that  
> says to use SDLK\_LGUI, but SDL doesn’t seem to recognize that on my  
> setup (it says: ‘SDLK\_LGUI’ was not declared in this scope).
> 
> I’m using SDL1. My IDE is Xcode 3.2.6, and I’m on an iMac, running OSX  
> 10.6. I should also probably mention that I’m still pretty new to SDL  
> and C++, so I might have trouble getting my head around some of the more  
> advanced stuff!

In SDL2, this is SDL\_LGUI (or RGUI, left and right).

In SDL1, this is SDL\_LMETA (or RMETA).

(ps: Use SDL2 unless there’s a really good reason to use SDL1. You’ll  
thank me later.)

–ryan.

---

<div class="post-metadata">

**Author:** ![Explodey](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/e/ecb155/32.png) [@Explodey](https://discourse.libsdl.org/u/Explodey)\
**Post date:** [May 16, 2014, 3:48am UTC](https://discourse.libsdl.org/t/how-do-i-get-the-key-state-of-the-apple-key/20683/3 "2014-05-16T03:48:46Z")

</div>

Thanks Ryan, that did the trick. Btw, the reason I’m learning SDL1 is because the only book on SDL2 that I could find (SDL Game Development) was too advanced for me. I chose “Focus on SDL” because, even though it’s outdated, it’s written in a way that makes sense to me. I know there are online tutorials, but I prefer real ink and paper books.

---

<div class="post-metadata">

**Author:** ![Edward\_Rudd](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/edward_rudd/32/180_2.png) [@Edward\_Rudd](https://discourse.libsdl.org/u/Edward_Rudd)\
**Post date:** [May 19, 2014, 2:55pm UTC](https://discourse.libsdl.org/t/how-do-i-get-the-key-state-of-the-apple-key/20683/4 "2014-05-19T14:55:33Z")

</div>

For OpenGL use there isn’t too much different between SDL1 and SDL2… The event processing APIs are largely the same, and most other APIs are either the same or very similar. the biggest change is there is no SDL\_SetVideoMode… instead you do this

SDL\_Window \*mywin = SDL\_CreateWindow(“My Awesome Game”, SDL\_WINDOWPOS\_UNDEFINED, SDL\_WINDOWPOS\_UNDEFINED, 800, 600, SDL\_WINDOW\_OPENGL);

SDL\_GLcontext myglCtx = SDL\_GL\_CreateContext(mywin);

… use OpenGL and do your standard event loop ?

And actually with SDL2 there is a much broader set of test examples in the test folder in the source.

So once you get your feet wet with SDL, please do switch to SDL2 asap. as that’s where all the development and modern OS support is at.

Edward Rudd  
OutOfOrder.cc  
Skype: outoforder\_cc  
317-366-7906On May 15, 2014, at 11:48 PM, Explodey wrote:

> Thanks Ryan, that did the trick. Btw, the reason I’m learning SDL1 is because the only book on SDL2 that I could find (SDL Game Development) was too advanced for me. I chose “Focus on SDL” because, even though it’s outdated, it’s written in a way that makes sense to me. I know there are online tutorials, but I prefer real ink and paper books.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
