2011-11-29 44 views
0

我想通過藍牙訪問鍵盤。如何在Android中通過藍牙訪問鍵盤?

例如: 如果我在第一個設備中打開鍵盤並且我想在任何編輯文本中訪問另一個設備中的鍵盤,則兩個設備通過藍牙相互連接。

所以,我怎麼能訪問該鍵盤在另一臺設備通過藍牙在android系統?

回答

0

要檢測的EditText鍵盤彈出:

Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    final int proposedheight = MeasureSpec.getSize(heightMeasureSpec); 
    final int actualHeight = getHeight(); 

    if (actualHeight > proposedheight){ 
     // Keyboard is shown 
    } else { 
     // Keyboard is hidden 
    } 

    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
} 

要捕捉的關鍵事件

final EditText edittext = (EditText) findViewById(R.id.edittext); 
edittext.setOnKeyListener(new OnKeyListener() { 
    public boolean onKey(View v, int keyCode, KeyEvent event) { 
     // If the event is a key-down event on the "enter" button 
     if (event.getAction() == KeyEvent.ACTION_DOWN) 

     // keycode should be sent over bluetooth. 

      return true; 
     } 
     return false; 
    } 
}); 

要在活動注入按鍵只需調用onKeyDown()用適當的KeyEvent


開闢鍵盤

EditText editText = (EditText) findViewById(R.id.myEdit); 
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
// only will trigger it if no physical keyboard is open 
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 

並關閉它:

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0); 

如果你不感興趣的其他手機上彈出鍵盤,簡單地忽略這一部分。使用好老:setText()


現在,你是如何形成的通過藍牙發送這些關鍵事件是高達you.Hint聊天協議:RemoteDroid used OscMessages

+0

@ Reno ..但我沒有使用edittext ...我想訪問第一個設備鍵盤到另一個設備的任何編輯器(Edittext)...所以我怎麼能在edittext中獲得這些鍵:例如,如果我想在另一臺設備上輸入用戶名和密碼,然後我可以訪問第一個設備鍵盤 –

+0

你,你說什麼?你不使用的EditText的但你要使用的EditText?我無法理解你的意思。 – Reno

0

如果你想要的是有手機的人按一個鍵與鍵進入上話機B當前突出顯示的字段,那麼這是你所需要的:

兩部手機上的應用程序(一個在「發送模式」,一個在「接收模式」)。

您需要捕獲按鍵在@Reno的回答編碼。然後您需要使用傳輸機制(在這種情況下爲藍牙)將其傳輸到其他設備。你應該能夠搜索到足夠多關於通過藍牙傳輸字符串的教程。

你需要在手機B中的應用程序來接收字符串/字符,然後輸出到當前選定的領域。這意味着找到關注的領域(再次,在那裏回答SO),然後寫入該領域(可能是setText("A");)。