2011-11-02 19 views
1

我希望能夠在iOS應用中檢測物理鍵盤(例如藍牙)事件。iOS響應物理鍵盤事件和UIInternalEvent

我遇到這個帖子:iOS: how to respond to up/down/left/right arrow event from physical keyboard?這表明在騎UIApplication:sendEvent。

在騎UIApplication後,我可以知道按鍵是「UIInternalEvent」,並且不適合3種記錄的事件類型之一。使用調試器時,我無法區分用戶單擊「左箭頭」時單擊「a」的位置。有什麼建議麼?

我的代碼:

- (void)sendEvent:(UIEvent *)event{ 
    UIEventType u = [event type]; 

    if(u != UIEventTypeTouches){ 

    } 
    [super sendEvent:event]; 
} 

調試斷點是if語句內。

編輯:顯然UIInternalEvent是GSEvent的包裝。 GSEvent信息可以在這裏找到:https://github.com/kennytm/iphone-private-frameworks/blob/master/GraphicsServices/GSEvent.h但我仍然不知道如何使用它。

回答

1

使用私人框架GraphicsServices交易,你可以使用的UIEvent對象獲得GSEventRecord中的中的SendEvent UIApplication的。更多少這樣的:

GSEventRef e = [UIEventObject _gsEvent]; 
const GSEventRecord *record = GSEventGetGSEventRecord(e); 

然後嘗試在看記錄結構的標誌值,當你按shift,控制等改變