OSX: detect SPACEBAR down and up events

不羁岁月 提交于 2020-01-04 02:50:18

问题


I need to record several thousand short soundbites of my own speech (I'm training an acoustic model for a speech recognition engine)

So for each one, a line of text presents itself on the screen and I have to speak it, and capture the audio into a .WAV

I found a sample project for recording the audio; now I am trying to figure out how to do keyboard input.

I would like to push the SPACEBAR down to start recording and release it to terminate the recording.

Can anyone get me started? ( an example would be ideal! )

Sorry, this is probably really really basic -- I haven't done any coding in OS X before (though I have done a lot of iOS work so I am no stranger to Xcode and some of the frameworks)


回答1:


If you create a basic Cocoa application, you can use the following methods of NSResponder, of which NSView is a subclass, to capture your desired key up/down events:

-(void)keyDown:(NSEvent*)event;
-(void)keyUp:(NSEvent*)event;

Use [event keyCode] to get the key pressed.



来源:https://stackoverflow.com/questions/8198109/osx-detect-spacebar-down-and-up-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!