“推动制作”键盘按键的风格使用
我正在 Fedora Linux 中使用 C 来构建语音流应用程序。我在两个客户端之间运行音频,但下一阶段是实现用户界面。
我的目标是以“一键通话”方式使用不同的键盘按键,即按住“Q”键允许用户与一个用户交谈,“W”键允许用户与另一个用户交谈,依此类推。
我的问题是,我将如何实施这个?传输线程只是一个 while 循环,它从声卡读取 180 个字节并将其作为 UDP 数据包发送。最明显的问题是按键的回声,用 q 和 w 填充屏幕,以及如何在 C 中检测按键按下/按键按下。我正在查看 ncurses,但这是一个很大的主题!
任何想法或进一步阅读将不胜感激。
J
I am using C in Fedora Linux to build a voice streaming application. 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.
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. 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!
Any ideas or further reading would be greatly appreciated.
J
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题的第一部分,关于如何在不使用
ncurses
的情况下检测按键是 使用termios
很好地回答了,作者:@jim mcnamara并且
ncurses
似乎并不那么可怕声音:-)。 这里是一个ncurses
实现,它完全(几乎)满足你的要求。但根据 这篇文章,您需要添加notimeout( )
调用,以便getch()
(ncurses one) 不会等待下一次按键。The first part of your question, as to how to detect keypress without using
ncurses
is answered excellently, usingtermios
, by @jim mcnamaraAnd
ncurses
doesn't seem to be as scary as it sounds :-). Here is anncurses
implementation which exactly ( almost ) satisfies your requirement. But according to this post, you need to add anotimeout()
call so thatgetch()
(ncurses one) doesn't wait for next keypress.