# GetKeyboardState() problems/usage

**URL:** <https://www.ruby-forum.com/t/getkeyboardstate-problems-usage/171781>\
**Category:** Ruby\
**Created:** [July 9, 2009, 6:29am UTC](https://www.ruby-forum.com/t/getkeyboardstate-problems-usage/171781 "2009-07-09T06:29:07Z")\
**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 9, 2009, 6:29am UTC](https://www.ruby-forum.com/t/getkeyboardstate-problems-usage/171781/1 "2009-07-09T06:29:07Z")

</div>

What seems to be the correct means of using this function?

getState = Win32API.new(‘user32’,‘GetKeyboardState’,[‘P’],‘N’)

byteGrid = 0.chr \* 256 #for the 256 virtual keycodes

now, using getState.call(byteGrid) changes some of the /000’s to /001’s  
respectively.

However, how might one call back what virtual codes (keys) were  
activated?  
It’d be nice to have the functionality of getState(68) =\> 1 or something  
of the sort… 68 representing “D” of course in ascii.

Any ideas?

Thanks,

- Mac
