[英]“Push-to-make” style use of keyboard keys
I am using C in Fedora Linux to build a voice streaming application. 我在Fedora Linux中使用C来构建语音流应用程序。 I have audio running between two clients, but the next stage is to implement the user interface.
我在两个客户端之间运行音频,但是下一步是实现用户界面。
I am aiming to use different keyboard keys in a "push to talk" style, ie holding the "Q" key allows the user to talk to one user, "W" another and so on. 我的目标是以“一键通”的方式使用不同的键盘键,即按住“ Q”键允许用户与一个用户交谈,“ W”与另一个用户交谈,依此类推。
My question is, how would I go about implementing this? 我的问题是,我将如何实施呢? The transmit thread is just a while loop that reads 180 bytes from the sound card and sends it as a UDP packet.
传输线程只是一个while循环,它从声卡中读取180个字节并将其作为UDP数据包发送。 THe mist obvious issue is echoing of the key pressed, filling the screen with q's and w's, and how I can detect key down/key up in C. I am looking at
ncurses
but it is a big topic! 薄雾明显的问题是回声所按下的键,用q和w填充屏幕,以及如何检测C中的向下/向上键。我正在看
ncurses
但这是一个大话题!
Any ideas or further reading would be greatly appreciated. 任何想法或进一步阅读将不胜感激。
J Ĵ
The first part of your question, as to how to detect keypress without using ncurses
is answered excellently, using termios
, by @jim mcnamara 关于问题的第一部分,关于如何在不使用
ncurses
情况下检测按键,使用termios
很好地回答了@jim mcnamara
And ncurses
doesn't seem to be as scary as it sounds :-). 而且
ncurses
似乎并不像听起来那样可怕:-)。 Here is an ncurses
implementation which exactly ( almost ) satisfies your requirement. 这是一个
ncurses
实现,它完全(几乎)满足您的要求。 But according to this post , you need to add a notimeout()
call so that getch()
(ncurses one) doesn't wait for next keypress. 但是根据这篇文章 ,您需要添加一个
notimeout()
调用,以使getch()
(ncurses一个)不会等待下一次按键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.