# Speeding up GetAsyncKeyState

**URL:** <https://www.ruby-forum.com/t/speeding-up-getasynckeystate/171417>\
**Category:** Ruby\
**Created:** [July 2, 2009, 3:36am UTC](https://www.ruby-forum.com/t/speeding-up-getasynckeystate/171417 "2009-07-02T03:36:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [July 2, 2009, 3:36am UTC](https://www.ruby-forum.com/t/speeding-up-getasynckeystate/171417/1 "2009-07-02T03:36:53Z")

</div>

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

GetAsyncKeyState is representing Win32API.new(‘user32’,  
‘GetAsyncKeyState’, [‘i’], ‘i’)

and keys represents a hash of scan code to virtual keycode conversions.

The problem occurs as seen 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.

Any way to speed this up?

Regards,

- Mac
