# QWERTY support in HME



## wmcbrine

...is finally here, as noted elsewhere, as of 11.0h (for S3/HD) or 14.5 (for Premiere). But of course, as with other recent changes to HME, the method hasn't been published. Here's what I've found out about it:

It uses key events, with a code of 0 (KEY_UNKNOWN), and the actual key value stored in the rawcode. The rawcode always has an LSB of 0, with the MSB starting at 0x3c for "A". For most keys, only release and repeat events are reported, not presses. My list so far:

((rawcode & 0xff00) >> 8) - 0x3c

0-25: A-Z
26: -
27: =
28: [
29: ]
30: \
31: ;
32: '
33: ,
34: .
35: /
36: `
37: Space
38: Tab*

42: Ctrl_Left*
43: Crtl_Right*

50: PgUp*
51: PgDn*
52: Home*
53: End*
54: Insert*
56: Delete*

* Reports both press and release; other keys only report release and 
repeat.

The function keys, arrow keys, and Enter return regular remote codes, as previously reported. What I didn't realize before is that you can also use the rawcode to distinguish between QWERTY input and regular remote input, if for some perverse reason you wanted to.

This is all with a plain 104-key USB keyboard plugged into my S3; I haven't tried other devices yet.


----------



## wmcbrine

OK, for anyone wondering, I can confirm that this also works with network remote input via the KEYBOARD command, though sadly only on the Premiere at this time.


----------



## davidblackledge

Nice, thank you. Frustrating, though. I've got a dozen things in my head I've been wanting to do in HME, and now this to add to my keyboards, but I haven't even had time to balance my checkbook for the past few months, much less have some fun.

Does the numbering scheme look familiar to anyone?
A quick JavaScript charCodeAt check says A==65 (0x3C==60) and a==97 and of course space==32 but above looks like HME has THAT at 97. Of course it's rawcodes, so I don't expect it to follow ASCII, but it starts so close, you'd at least think they'd align A-Z.

*SIGH*... can somebody give me vacation time and clean my house and organize my garage so I can have some time, please?


----------



## wmcbrine

I've been unable to match it to ASCII, keyboard scan codes, or anything else. I'm sure there's a logic to it, but it's obscure.


----------



## wmcbrine

wmcbrine said:


> OK, for anyone wondering, I can confirm that this also works with network remote input via the KEYBOARD command, though sadly only on the Premiere at this time.


...although it has since emerged that it now works with IRCODE on the Series 3 and HD, instead of KEYBOARD.


----------



## davidblackledge

(yes, I'm cross-posting, please don't shoot me... not like anything goes on in this forum anyhow)
I've written up the mapping on the hmedev wiki (in the "HME Discovered" section). The page is a "complete" mapping of what the USB keyboard can do and what it I believe it maps to on the Slide Remote.
There are a couple of gaps at this moment, but hopefully they'll soon be filled in. (yes, some gaps are just pure laziness - you probably know what to fill in for half of them without even trying it out) A couple of things are my best guess without a Slide Remote to check it out.
http://hmedev.wikidot.com/slide-remote-keyboard-support

The big unknown is what the 'sym' key sends... so for now I'm just implementing all unknown keys as acting like the 'sym' key. However, I'm sure the "on demand" button or perhaps the A/B/C/D (I forgot to include those in the mapping at the moment) may be some of those uknowns.

Send me a slide remote, and I'll fill in the gaps ;]

Yes, I tried ctrl, shift, etc. combinations. The support is only single keys, no modifier combinations.


----------



## wmcbrine

davidblackledge said:


> adjusted raw code = (int)(((rawcode & 0xff00) » 8) - 0x3c); per William McBrine, but taking into account known keys, the -0x3c shouldn't be applied so arrows can start at 0 instead of -60


I don't know why you say this. The formula is only meant to be applied to the rawcode when the key code is KEY_UNKNOWN. The arrow keys return proper key codes of their own, so there is no reason to refer to the rawcode in those cases.

Anyway, I have a Slide remote, so I just tried this. Sym does not generate an HME event, nor does Cap, nor (alas) does the Backspace key. Also, Cap has no effect on the key code or rawcode sent when the next key is pressed (nor is it meaningful to hold it down). This is with a Premiere, running 14.6.

It seems clear from the TiVo's behavior on internal menus, as well as the flashing blue light on the remote, that Sym and Cap _are_ sent to the TiVo as discrete presses; they just aren't passed on to HME.

I also found that some of my previously-determined symbol codes didn't match what the Slide shows, so I'll have to look at that more closely.


----------



## wmcbrine

...although I notice that the backspace key works in, e.g., the Music Choice HME app, so there must be a way to get at it. Perhaps the TiVo behaves differently depending on the version of the HME protocol reported by the app?

Edit: Yep, it sure does. I bumped the minor version to 50 49, and I get codes from backspace. What's more, I seem to get both KEY_PRESS and KEY_RELEASE events now! I'll explore further...

Edit 2: ...although the KEY_PRESS events don't match the KEY_RELEASES! (That's for alpha keys; backspace is mapped like a regular key.) Different key codes _and_ rawcodes.

Edit 3: ...and from the network interface, IRCODE _does_ produce the same codes for press and release events, while KEYBOARD matches the behavior of the Slide (and other USB keyboards). Things are starting to make more sense now.


----------



## wmcbrine

The KEY_PRESS code for these "advanced" events is 0x10000 + ASCII. It _is_ affected by the Cap key (pressed first, separately). However, the KEY_RELEASE event is as before.


----------



## davidblackledge

wmcbrine said:


> Perhaps the TiVo behaves differently depending on the version of the HME protocol reported by the app?
> 
> Edit: Yep, it sure does. I bumped the minor version to 50 49, and I get codes from backspace.


Sweet. This could be the source for answers for some other reverse engineering problems, too.

You wouldn't have a moment to update the wiki with the codes your finding, would you? If you prefer, you can just buy me a Slide remote and I'll do it.

(oh, and regarding my "don't subtract 60" comment... the one grey area that makes my comment worthwhile is F12 - it doesn't have a standard key code, and its adjusted raw code is -46 or something.)


----------



## davidblackledge

I played around with a USB keyboard on TiVo Search "beta" this morning and found some more interesting stuff.

Caps Lock - it exited the TiVo Search application gracefully and silently (even when the cursor wasn't on the far left of the screen keyboard), but it actually performed the Caps Lock function as well. Initially my letters were all capitals, then when I came back in 1) my so-far search string was still there and 2) my added letters were lowercase now.

Shift - as you indicated, it did something - it reversed the current capslock state for letters. I thought it didn't work for symbols and numbers, but that's because I was in CapsLock mode initially... once I had CapsLock off, shift worked for numbers (Shift 1 gave me !) and symbols (shift , gave me <) - this makes me think [sym] is just internal to the Slide Remote, not an event, although as you said, it flashes the blue light on the remote so I can't be sure.

Backspace key - works on the USB keyboard in a "modern" app, so it must correspond to the ← (back arrow) on the slide remote. Unfortunately the Delete key did nothing in TiVo Search.

Alt and Windows key - interestingly enough, they cancelled capitalization when CapsLock was on (but they didn't act as an alternate shift key since cancelling capitalization was the only thing it did in conjunction with any key)

None of the other known keys with no known functionality (F12, print screen, home/end/insert, tab, etc) seemed to do anything to activate a symbol or anything interesting (either hitting it beforehand or holding it down while hitting another key). Not even the control keys.
Also of interest: the USB numpad is still as I stated in the Wiki - / and - work, while * and + don't... and when Shift is working (when CapsLock is off) - makes _ and / makes ? as if it was from the main keyboard.
I didn't notice for certain, but I don't think the capslock light reflected the capslock mode.

Hopefully I'll have the time to do something about that HME Version string this weekend or something so I can document the codes involved here.


----------



## davidblackledge

davidblackledge said:


> \I've written up the mapping on the hmedev wiki (in the "HME Discovered" section). The page is a "complete" mapping of what the USB keyboard can do and what it I believe it maps to on the Slide Remote.
> http://hmedev.wikidot.com/slide-remote-keyboard-support


Thanks to wmcbrine's discovery about minor version 49, I've "finished" the documentation on the wiki, especially regarding the new key codes which means we don't need to worry about weird mappings anymore. It's just about 7 codes plus ASCII space through tilde.

If you're using the Java SDK, you'll have to use a Factory, override a couple of methods that send the version number with copies that use a 49, copy a couple of other methods to make them accessible, and make your application's setContext methods an override just so it's accessible from the factory method you're overriding.

Yay!


----------



## wmcbrine

I'm not sure why I didn't notice this before, but the Cap key on the Slide _does_ generate an event, in HME 0.49 mode -- just not at the time you press it. What happens is, once you press the next key (the key to be capitalized), you get back a sequence that looks like this:

KEY_PRESS: Shift
KEY_PRESS: A
KEY_RELEASE: A
KEY_RELEASE: Shift

Now, the "A" in this case is sent with what I'm calling the type 2 direct text event -- ASCII + 0x10000 -- so the case is conveyed anyway, and the shift key event isn't really adding anything. But it's interesting.

The shift key code used is 71.


----------

