So here is the jist of Anton's code:
Capture mouse (Sketchup will stop reacting to it):
getForegroundWindow=Win32API.new("user32", "GetForegroundWindow", [], "L")
Win32API.new("user32", "SetCapture", "L", "L").call(getForegroundWindow.call())
Read all key states (keyboard and mouse):
@getKeyboardState=Win32API.new("user32", "GetKeyboardState", "P", "V")
@lpKeyState=" "*256
@getKeyboardState.call(@lpKeyState)
@lpKeyState will hold an array of 256 numbers for all the keys.
@lpKeyState[1,2,4] - [1]left-mouse, [2]right-mouse, [4]middle-mouse
@lpKeyState[48..57] - keyboard keys 0 to 9
Release mouse
Win32API.new("user32", "ReleaseCapture", "V", "L").call()