Here is the problem:
GetAsyncKeyState = Win32API.new('user32','GetAsyncKeyState', ['i'], 'i')
while true
keys.each {|k, v| print k.upcase if GetAsyncKeyState.call(v) & 0x01 == 1 && GetAsyncKeyState.call(0x10) & 0x01 == 1}
keys.each {|k, v| print k.downcase if GetAsyncKeyState.call(v) & 0x01 == 1}
end
##keys represents a hash of scan code to virtual keycode conversions.
The problem occurs by running this in a console... pressing "a"
too quickly results in no secondary "a".
In short... it doesn't pick up all the keyboard input unless you type at
1 letter per 3 seconds. Almost like it is cycling through the virtual
keycodes and doesn't get back around to "a" in time.
Not "almost like": Exactly like! You have this TWICE per loop:
keys.each { ... }
so you're cycling through all the virtual keycodes twice per loop and you're calling GetAsyncKeyState at least keys.size * 2 times per loop. I'm sure you can rewrite this to only have one call to each per loop with minimal effort. I doubt that you need to have both upcase and downcase. Prolly only one is needed depending on the keys in keys, but that won't speed up much at all.
My guess is that there is a much more efficient way to do what you want to do... like, don't put everything in keys, just the 5-10 you're actually interested in (assuming you're doing a game or something)...
I'll also bet that whatever you do doesn't work with the dvorak layout, which would make me sad, except that you're developing on a platform I try not to use to begin with. 
P.S. Use a constant instead of 0x10
P.P.S. It'd be nice if you got your return/enter key fixed.
P.P.P.S. loop do ... end
···
On Jul 6, 2009, at 22:22 , Michael Linfield wrote: