I\'ve written an Android app that connects to a Bluetooth keyboard. It connects through a BT socket to the keyboard and acquires the socket\'s input stream.
Some Galaxy Tabs support the HID protocol, some don't. It depends on the carrier, not on Samsung. My Verizon Galaxy Tab came without HID support even though the T-Mobile ones had it. But in April of this year Verizon (not Samsung) pushed out a firmware upgrade that included HID support so my BT keyboard & mouse started working. I'm running Android 2.2, and my firmware build number is SCH-I800.EC02.
It's my guess that you're trying to do this because your Tab won't connect to the BT keyboard at all. This is exactly what I was trying to do before April. From what I remember reading, the magic incantation part is supposed to be handled by Android automatically: when you make the HID connection, Android pops up a message window to enter a code on the keyboard, then the socket connection is returned to your program (or something to that effect).
So if you can't get the Tab to connect to the keyboard normally, then your HID profile has been disabled and (afaik) no amount of programming will make it work, except maybe a rewrite of the HID profile in Java.
I'm sure you tried this already, but to test it go to Settings > Wireless and Networks > Blutetooth settings, you should see the keyboard in the list whether or not you have HID support. Tap the keyboard entry, it should connect right away. If it just delays indefinitely or if you get an error message, then you have no HID support.