IonicWind Software

IWBasic => Console Corner => Topic started by: REDEBOLT on February 25, 2007, 04:37:41 PM

Title: INKEY$(1)
Post by: REDEBOLT on February 25, 2007, 04:37:41 PM
I understand the use of INKEY$(1) returns the virtual key codes.  However, I am puzzled as to how lower case letters and special characters are detected.  E.g., a lower case letter pressed is read as an upper case letter.  Obviously, I cannot use both INKEY$(1) and INKEY$ at the same time.
Title: Re: INKEY$(1)
Post by: Ionic Wind Support Team on February 25, 2007, 05:14:11 PM
Us GetKeyState to check for special keys.
Title: Re: INKEY$(1)
Post by: REDEBOLT on February 27, 2007, 05:14:11 PM
I constructed a program to detect the virtual keys with getkeystate.
It works fine, but it will not detect upper/lower case letters.
See line 30.  How can I detect these keys?
openconsole
$include "windows.inc"
string mykey
locate 1,1
print "GETKEYSTATE demonstration. ",
print "Press <ESC> to end program"
print "Press any other keys to display them"
locate 4,1

do
  do:until inkey$(1)<>""
  mykey = readkey()
  print mykey
'  inkey$()
until getkeystate(VK_ESCAPE)
closeconsole
end

sub readkey(),string
if getkeystate(VK_PRIOR) then return "PgUp"
if getkeystate(VK_NEXT) then return "PgDn"
if getkeystate(VK_END) then return "End"
if getkeystate(VK_HOME) then return "Home"
if getkeystate(VK_INSERT) then return "Insert"
if getkeystate(VK_DELETE) then return "Delete"
if getkeystate(VK_LEFT) then return chr$(27)
if getkeystate(VK_UP) then return chr$(24)
if getkeystate(VK_RIGHT) then return chr$(26)
if getkeystate(VK_DOWN) then return chr$(25)
return inkey$()
end sub

???
Title: Re: INKEY$(1)
Post by: LarryMc on February 27, 2007, 06:41:48 PM
see if this will help a little:
def a,b:string
$include "windows.inc" 
OPENCONSOLE   
CLS   
print: print "Press any key to continue, q to quit."   
do
   do
    a = INKEY$(1):REM return virtual key codes
   until (a <> "") 
   b = a 
   if a = CHR$(0x09) then b = "Tab"
   if a = CHR$(VK_LEFT) then b = "LeftArrow"
    if a = CHR$(VK_UP) then b = "UpArrow"
    if a = CHR$(VK_RIGHT) then b = "RightArrow"
    if a = CHR$(VK_DOWN) then b = "DownArrow"
if a = CHR$(VK_PRIOR) then b = "PgUp"
if a = CHR$(VK_NEXT) then b = "PgDn"
if a = CHR$(VK_END) then b = "End"
if a = CHR$(VK_HOME) then b = "Home"
if a = CHR$(VK_INSERT) then b= "Insert"
if a = CHR$(VK_DELETE) then b = "Delete"
if a = CHR$(0x70) THEN b = "F1"
if a = CHR$(0x71) THEN b = "F2"
if a = CHR$(0x72) THEN b = "F3"
if a = CHR$(0x73) THEN b = "F4"
if a = CHR$(0x74) THEN b = "F5"
if a = CHR$(0x75) THEN b = "F6"
if a = CHR$(0x76) THEN b = "F7"
if a = CHR$(0x77) THEN b = "F8"
if a = CHR$(0x78) THEN b = "F9"
if a = CHR$(0x79) THEN b = "F10"
if a = CHR$(0x7A) THEN b = "F11"
if a = CHR$(0x7B) THEN b = "F12"

    if a = CHR$(0x51) then b = "q"
    locate 4,2
   print "Key: ",b+"  ",
  until b="q"
  print
  print "Press Enter to quit:", : 'still shows q 
input  b   
CLOSECONSOLE
   END   
Title: Re: INKEY$(1)
Post by: REDEBOLT on March 12, 2007, 10:05:34 AM
How may I obtain the handle to the console window?
Title: Re: INKEY$(1)
Post by: Parker on March 12, 2007, 08:11:24 PM
The short answer is that you don't. You're not really supposed to manipulate the console that way.

The long answer is that you use SetConsoleTitle and FindWindow to get the handle using a unique window title. I know Aurora has a built in SetConsoleTitle function, though I'm not sure about EBASIC. It's in the windows API though (MSDN Online Reference (http://msdn.microsoft.com/)). Once you have set a unique title, you search for that window. FindWindow will give you a handle, which will be the handle to your console window.
Title: Re: INKEY$(1)
Post by: Sean on May 10, 2007, 11:42:33 AM
ConsoleReadHdl=GetStdHandle(-10)
ConsoleWriteHdl=GetStdHandle(-11)

might have those backwards.