Midi-Messages from an item can be gotten from the Items themselves, namely ItemStateChunks. In there, you can read all MIDI-messages in the <Source tag.
There is a documentation in Cocko's-Wiki, though it's probably outdated:
https://wiki.cockos.com/wiki/index.p...nk_Definitions
Midi-Messages from devices can probably be gotten only in JSFX, as far as I know.
Unfortunately, there is currently no way to communicate between JSFX and Lua, beside using automation-parameters for communication(which would be more of a hack than a clean solution).
Get_action_context is too limited to really be useful for what you want to achieve.
We definately need more MIDI-access in Reaper's Api.
Dunno if SWS could do more about that and expose stuff to the API. As SWS is a C++-plugin, they usually have more access to Reaper's internals...