# how to detect key pressed on linux console app?

**URL:** <https://forums.swift.org/t/how-to-detect-key-pressed-on-linux-console-app/5645>\
**Category:** Using Swift\
**Created:** [April 11, 2017, 5:04am UTC](https://forums.swift.org/t/how-to-detect-key-pressed-on-linux-console-app/5645 "2017-04-11T05:04:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrBee](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mrbee/32/2312_2.png) [@MrBee](https://forums.swift.org/u/MrBee)\
**Post date:** [April 11, 2017, 5:04am UTC](https://forums.swift.org/t/how-to-detect-key-pressed-on-linux-console-app/5645/1 "2017-04-11T05:04:34Z")

</div>

Hi all,  
I'd like to know how to detect key pressed event on Linux console app using Swift. Not just waiting input like what readLine() is doing, but more like detecting arrow keys, left/right shift key, F1-10 keys, etc simultaneously while the program keep running. You know, something like game input.  
Thank you.  
Regards,  
–Mr Bee

---

<div class="post-metadata">

**Author:** ![saagarjha](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@saagarjha](https://forums.swift.org/u/saagarjha)\
**Post date:** [April 12, 2017, 2:20am UTC](https://forums.swift.org/t/how-to-detect-key-pressed-on-linux-console-app/5645/2 "2017-04-12T02:20:11Z")

</div>

AFAIK there isn’t a way to do this in Swift; you’ll have to drop down to C and use something like getchar or a library like ncurses. If I recall there was some discussion a while back about better command-line APIs for Swift but it appears that it fizzled out with the Swift 3 deadline and all.

Saagar Jha

> **···**
>
> > On Apr 10, 2017, at 22:04, Mr Bee via swift-users \<swift-users@swift.org\> wrote:
> > 
> > Hi all,
> > 
> > I'd like to know how to detect key pressed event on Linux console app using Swift. Not just waiting input like what readLine() is doing, but more like detecting arrow keys, left/right shift key, F1-10 keys, etc simultaneously while the program keep running. You know, something like game input.
> > 
> > Thank you.
> > 
> > Regards,
> > 
> > –Mr Bee
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-users mailing list  
> > swift-users@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-users](https://lists.swift.org/mailman/listinfo/swift-users)
