I need to understand some User32.dll functions and I’m making an
GUI so I can easily experiment with different parameters. This is taking
long time. I’m new to python and ruby and I’m thinking it would sure be
to have an interpreter I can type a few lines of code into and test
(1) Would CRuby be a good choice for this? How about iron ruby? How
JRuby (probably not).
(2) What about callbacks? Which rubys can handle callbacks? I read on
that you cannot use managed code to call SetWindowsHook and supply a
back (with two exceptions). I guess that means I cannot use iron ruby.
about C-ruby for playing with hooks?
(3) How easy it it define the C structs, enums and integer constants
necessary to call the windows API functions?
(4) Here is the code I’m struggling with presently (it is just not
cooperating: no errors just wrong results! I expect to be able give it a
scan code, get a virtual key code, change the arguments, give it the
key code and get the original scan code back again).
public const UInt32 MAPVK_VK_TO_VSC = 0, MAPVK_VSC_TO_VK = 1,
MAPVK_VK_TO_CHAR = 2, MAPVK_VSC_TO_VK_EX = 3, MAPVK_VK_TO_VSC_EX = 4;
public const UInt32 KLF_ACTIVATE = 1, KLF_SUBSTITUTE_OK = 2,
KLF_REORDER = 8, KLF_REPLACELANG = 0x10, KLF_NOTELLSHELL = 0x80,
KLF_SETFORPROCESS = 0x00100, KLF_SHIFTLOCK = 0x10000, KLF_RESET =
[DllImport(“user32.dll”)] static extern IntPtr
LoadKeyboardLayout(string pwszKLID, uint Flags);
[DllImport(“user32.dll”)] static extern bool
[DllImport(“user32.dll”)] static extern uint
uCode, uint uMapType, IntPtr dwhkl);
private void Compute()
IntPtr hkl = LoadKeyboardLayout(sLangId_, KLF_ACTIVATE |
KLF_SUBSTITUTE_OK | KLF_REPLACELANG);
uResult_ = MapVirtualKeyEx(uCode_, uMapType_, hkl);
Would it be easy to execute this in the CRuby interpreter or am I better
sticking with C#?