Fix OSX keydown detection. I noticed that the OSX implementation differs from Linux and Windows, and it will trigger continuously for a key that is pressed down. It would totally make sense to change this to a callback driven model, but that's a bigger change.
I need to test this before committing... R=tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1996004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4550 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
c92781737c
commit
cc9238e385
@ -56,6 +56,8 @@ namespace webrtc
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
|
||||
|
||||
enum
|
||||
{
|
||||
MaxNumberDevices = 64
|
||||
@ -153,7 +155,8 @@ AudioDeviceMac::AudioDeviceMac(const int32_t id) :
|
||||
_paCaptureBuffer(NULL),
|
||||
_paRenderBuffer(NULL),
|
||||
_captureBufSizeSamples(0),
|
||||
_renderBufSizeSamples(0)
|
||||
_renderBufSizeSamples(0),
|
||||
prev_key_state_()
|
||||
{
|
||||
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id,
|
||||
"%s created", __FUNCTION__);
|
||||
@ -3259,14 +3262,20 @@ bool AudioDeviceMac::CaptureWorkerThread()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioDeviceMac::KeyPressed() const{
|
||||
|
||||
bool AudioDeviceMac::KeyPressed() {
|
||||
bool key_down = false;
|
||||
// loop through all Mac virtual key constant values
|
||||
for (int key_index = 0; key_index <= 0x5C; key_index++) {
|
||||
key_down |= CGEventSourceKeyState(kCGEventSourceStateHIDSystemState,
|
||||
key_index);
|
||||
// Loop through all Mac virtual key constant values.
|
||||
for (unsigned int key_index = 0;
|
||||
key_index < ARRAY_SIZE(prev_key_state_);
|
||||
++key_index) {
|
||||
bool keyState = CGEventSourceKeyState(
|
||||
kCGEventSourceStateHIDSystemState,
|
||||
key_index);
|
||||
// A false -> true change in keymap means a key is pressed.
|
||||
key_down |= (keyState && !prev_key_state_[key_index]);
|
||||
// Save current state.
|
||||
prev_key_state_[key_index] = keyState;
|
||||
}
|
||||
return(key_down);
|
||||
return key_down;
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
@ -285,7 +285,7 @@ private:
|
||||
bool RenderWorkerThread();
|
||||
|
||||
private:
|
||||
bool KeyPressed() const;
|
||||
bool KeyPressed();
|
||||
|
||||
private:
|
||||
AudioDeviceBuffer* _ptrAudioBuffer;
|
||||
@ -377,6 +377,11 @@ private:
|
||||
|
||||
int _captureBufSizeSamples;
|
||||
int _renderBufSizeSamples;
|
||||
|
||||
private:
|
||||
// Typing detection
|
||||
// 0x5c is key "9", after that comes function keys.
|
||||
bool prev_key_state_[0x5d];
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
Loading…
x
Reference in New Issue
Block a user