As per the title, running this simple script on Win and Mac results in different values for the same key (example: “S“ is 83 on Win and 1 on Mac). Is this expected? It would be weird if so, given that KeyboardEvent is a RhinoApp (and not a System) event, so it would make sense to have consistent codes for the same key in both OS.
If this is the expected behavior for some reason, how can I check that the same key (say “S“) is pressed when running on Win or on Mac? So far, I have used this check:
void OnKeyboardEvent(int key)
{
switch(key)
{
case (int)KeyboardKey.S:
// dosomethingelse
break;
case (int)KeyboardKey.W:
// dosomethingelse
break;
}
}
But it seems like KeyboardKey is mapped only on Win-based values. Running a script with the same check on Mac and pressing “S” won’t trigger the expected case.
The keyboard hook triggers a specific action (like rotating a selected geometry) in a plugin that, for now, I only tested on Windows; yesterday, I tried it on a Mac and found the problem. But the action per se is not important; let’s say I just want to print the key that was just pressed:
void OnKeyboardEvent(int key)
{
switch(key)
{
case (int)KeyboardKey.S:
Console.WriteLine("Hey, you pressed S!");
break;
case (int)KeyboardKey.W:
Console.WriteLine("Hey, you pressed W!");
break;
}
}
If you try this implementation of OnKeyboardEvent in my previous script and test it on Windows and Mac, the Windows version will spot the W and S keys correctly, while the Mac version won’t.
Since KeyboardKey is an enum of Rhino.UI, I expected it to work in Rhino regardless of the OS Rhino is running on. It is counterintuitive that it doesn’t.
Sure, I can hardcode the key values specifically for Windows and Mac with a preliminary check, but I was hoping for a more elegant solution. Shouldn’t RhinoCommon be OS-independent? (I mean, usable in both OS equally)