Hi,

2009/6/27 Michael Linfield <globyy3000 / hotmail.com>:
> Generally speaking, I want to use:
>
> Win32API.new('user32','GetAsyncKeyState',['i'],'i')
>
> in the same way as:
>
> Win32API.new('crtdll','_getch',[],'L').Call.chr
>
> #########
>
> I'm trying to take all of the user input typed into say a text document
> and modify it in realtime.
>
> Using GetAsyncKeyState with a hash of hex characters (because
> GetAsyncKeyState only generates a 0 or 1 depending on the state of the
> key)...only allows me uppercase letters... however _getch allows me to
> translate ascii into uppercase and lowercase.
>
> The problem with _getch is that it cannot be run in the background,
> hence the need to type directly into the shell... which would defeat the
> purpose of realtime manipulation of input.
>
> Any suggestions are much appreciated.
>
Here is a code snippet I used in the pure ruby readline.

require 'Win32API'
VK_LMENU = 0xA4
@getch = Win32API.new("crtdll", "_getch", [], 'I')
@kbhit = Win32API.new("crtdll", "_kbhit", [], 'I')
@GetKeyState = Win32API.new("user32","GetKeyState",['L'],'L')

if @kbhit.Call>0
    c = @getch.Call
    alt = (@GetKeyState.call(VK_LMENU) & 0x80) != 0
    if c==0 || c==0xE0
        r = c.chr + @getch.Call.chr
    else
        r = c.chr
    end
    r = "\e"+r if alt
    puts "#{r.inspect} pressed"
end while true


Hope this helps,

Park Heesob