Win32API keystate issue

M

Michael Linfield

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.

- Mac
 
H

Heesob Park

Hi,

2009/6/27 Michael Linfield said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top