Here's what I've got so far
Instead of using DI_HID_VENDORID, you should use DI_KBD_TYPE, since you're manipulating keyboards. Don't worry, it'll return the same values (since those two flags have the same constant value). It would look like this:
If (devh <> -1) ;Check that it is NOT my remote.
And (HID_GetDevInfo(devh, DI_KBD_TYPE, True) <> 81)
Also, a few AHK tricks

:
- Since AppActive is just a boolean variable, you can use AppActive := True and AppActive := False instead of = 0 and = 1. It's the same thing, but cleaner (and easier to read IMO).
- You can replace
If AppActive = 1
{
AppActive = 0
}
Else
{
AppActive = 1
}
by
AppActive := Not AppActive
- You can replace
If AppActive = 1
{
Run rundll32.exe user32.dll`,LockWorkStation`
}
by
If AppActive
Run rundll32.exe user32.dll`,LockWorkStation`
- If you don't need the prefix loop, you can remove it. Since you're using an OnMessage sub, your script is persistent, which means that it won't exit when it gets to Return.
Let me know if you have any other questions!
huh... just when I thought I was learning something
This is some complicated business =P
It's simple!

Look at the flags you can use with
HID_GetDevInfo(), all the ones starting by DI_MSE are for mice, DI_KBD are for keyboards, and DI_HID are for HID devices (the ones in the "Other" section of Example 1).
There are a couple quirks with a device like this.
I'm glad to hear it works! As for your problem, I'm sorry to tell you there's no way to "ask" the device what its status is. At least not with AHKHID. It really sucks that you have to rely on differentials to trigger the events. But I don't see a way around it. Sorry.

Also, is it realistic (i.e. fast enough) to hope to assign keystrokes on-the-fly in a GUI?
Sure! I don't see why not. There are different ways of implementing it, but it's totally doable. Personally, I don't mind quickly editing the script file so that I can change what each event does (and have a hotkey to reload the script).
If your goal is to be able to have multiple (different) actions for the same trigger, you might find modifier keys useful. For example, for one HID device I have (a USB volume knob), I use modifier keys to assign multiple actions for the same movement. For example, Ctrl+Turn controls the Master volume, while Shift+Turn controls the Wave volume.
There are other things you can do. For example, you can set the actions to execute to depend on the active window. Then, if you're in a game, it'll do something, but if you're not, it can do another thing.