C# BlueTooth Keystrokes

Topics: Bluetooth - Microsoft
Aug 13, 2012 at 2:05 AM

Hi,

I've got a C# application that can connect to a bluetooth device using a standard Bluetooth dongle. I am using Visual Studio 2010 in Windows 7.

Now i want to send keystrokes from my application to a device.  

I have an old Nokia phone and two iPhones (iphone 3 and iphone 4).  Ideally i would like to send data to the iPhone, but other platforms would be acceptable for this proof of concept.

How would i begin to do this? :-S 

 

Dan

Coordinator
Aug 13, 2012 at 9:18 AM

In order to do this without writing any software for the target device you would have to expose the HID (Human Interface Device) profile on the PC so that it appeared to the phone as a keyboard device. There isn't a ready made HID Server so you'd have to build this by following the HID profile spec. Windows has support built in for HID client (so that it supports Bluetooth keyboards) but not the reverse.

If you are writing software for both sides you can write a custom profile which is a lot simpler. However I'm not sure you would have the flexibility to write an app on iOS which would pass on the keystrokes to any application. The cleanest approach would be to go down the HID route, you may be able to implement this with only a subset of the full HID profile.

Peter

Aug 16, 2012 at 12:08 AM

Thanks for the response Peter.

Ok, so since i have established a connection.

http://code.google.com/p/pybtkeyboard/downloads/list

This is a Python example of a PC to Device Keyboard.  And from the code, all i can see is that it creates a steam and then writes ASCII code to this stream.

What am i missing?  There is also another small Java app for communicating with Android devices.

I am currenlty learning about the Brecham.Obex interface that seems to maintain sessions between PC and device in C#.  Once this is establish, would it not be possible to then write to the open stream?

My assumption is, if it can be done in Python, C# should have no problem.

Developer
Aug 19, 2012 at 9:05 PM

The main difficult bit with such a concept is getting the keystrokes etc recevied over Bluetooth to appear in the foreground running application. That will be very difficult on iPhone etc.  So see our samples BluetoothRemote. It works in the opposite direction to your concept. A program on Windows Mobile accepts keystrokes etc and send them to a program on PC with adds the keystrokes etc into the system buffers through SendKeys.

 

On the correct way to do this: HID.  It is likely impossible to get a HID device active on the MSFT Bluetooth stack, it could not coexist with the active HID host implementation. I've created simple HID device support that runs on Win32 (on cygwin or was it MinGW) but it uses Matthias Ringwald's btstack on a separate dongle.