April 19, 2024, 08:56:03 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


INKEY$(1)

Started by REDEBOLT, February 25, 2007, 04:37:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

REDEBOLT

February 25, 2007, 04:37:41 PM Last Edit: February 25, 2007, 04:40:18 PM by REDEBOLT
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.
Regards,
Bob

Ionic Wind Support Team

Us GetKeyState to check for special keys.
Ionic Wind Support Team

REDEBOLT

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

???
Regards,
Bob

LarryMc

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   
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

REDEBOLT

How may I obtain the handle to the console window?
Regards,
Bob

Parker

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). 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.

Sean

ConsoleReadHdl=GetStdHandle(-10)
ConsoleWriteHdl=GetStdHandle(-11)

might have those backwards.