Injected input returns "Unknown"

I have created a python application which takes MIDI input and injects it into the current application as text, like this: “C3”. I want to capture this input in ROBLOX, but when I try to print out the keycode name all alphabetical characters appear as “Unknown”.

image

Numeric characters seem to work, and so do hashtags.

If anybody knows a solution, I would be happy to hear of it.

(The output appears fine in Notepad.)

The keycode might be in a different byte format than what Roblox Lua uses so it might mix up things and display the “wrong” information, not knowing how to interpret it.

Lua and Python keycodes are likely different.
Tried converting keycodes to a single string or number that Lua CAN interpret correctly and then turn it into a Roblox keycode once it it received?

It requires two or more characters for multiple octaves. I’ll look into converting the string into something the (archaic) ROBLOX engine can understand.

EDIT: A hacky temporary solution could be just to replace the alphabetical notes with a number from 1 - 12.

1 Like

You could just use numbers/integers.

Both in Python and in Lua you can make a list or array of numbers and strings.

So… 1 = A, 2 = B, 3 = C, etc.
In python you convert it to numbers, if more than a single number has to be send over you could use a character to separate it.

Roblox Lua has a string.split() function I think which returns an array of strings.

so doing string.split("1;2;3;4;5", ";") would use ; as the splitting character.
This should return an array containing {"1", "2", "3", "4", "5"}.

Send over an array of numbers to Roblox containing numbers or send over a single string containing the numbers where each number is separated by a specific character.

Turn that back into an array, loop over the elements and turn each element into a keycode.

Let’s say in Roblox you got this table…

local keys = {
 ["1"] = Enum.KeyCode.A;
 ["2"] = Enum.KeyCode.B;
 ["3"] = Enum.KeyCode.C;
 ...
}

function toKeyCodes(str)
 local arr = string.split(str, ";")

 local keycodes = {}

 for i = 1, #arr do
  keycodes[#keycodes + 1] = keys[arr[i]]
 end
end

Hope that helps!
(This is pseudo code btw so it might not be 100% correct but should give you an general idea.)

1 Like