Author Topic: Can't get my console class to work  (Read 17578 times)

0 Members and 2 Guests are viewing this topic.

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #45 on: July 11, 2011, 09:24:01 PM »
Here is another strange problem. It is reading keyevent as wrong characters.
Pressing "x" will exit the program, but if you press other keys you will see the character codes don't match.

This program is console events, keyboard and mouse.

[attachment deleted by admin]

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #46 on: July 11, 2011, 10:41:48 PM »
Hi Kent,

Some tentative fiddling with the structure showed that a 4 byte alignment was required. Oxygen does not currently assume any particular alignment rules except for function address tables. But you can specify an align anywhere within the structure.

To inspect the structure encoding and offsets use:

#recordof KEY_EVENT_RECORD

It is a very useful diagnostic.

Code: OxygenBasic
  1.  
  2. type KEY_EVENT_RECORD
  3.         BOOL bKeyDown
  4.         WORD wRepeatCount
  5.         WORD wVirtualKeyCode
  6.         WORD wVirtualScanCode
  7. align 4
  8.         union uChar
  9.     {
  10.                 WCHAR UnicodeChar
  11.                 CHAR AsciiChar
  12.         }
  13.         DWORD dwControlKeyState
  14. end type
  15.  

Charles
« Last Edit: July 11, 2011, 10:45:06 PM by Charles Pegge »

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #47 on: July 11, 2011, 11:28:58 PM »
Thanks Charles, that will be new stuff for me to study.

kryton9

  • Guest
Getting Error Now
« Reply #48 on: November 11, 2011, 08:44:12 PM »
Charles, I am getting an error now with the ConsoleC.inc and any of the example programs from the first post.

ERROR:
Invalid constant: anumcharstoread
WORD:    charsread
FILE:    consolec.inc
LINE:    293

I can't figure it out, thanks.

Peter

  • Guest
Re: Can't get my console class to work
« Reply #49 on: November 12, 2011, 08:57:15 AM »
there are only consoles chaos over the christmas days !
the connection:  windows-oxygen-console  runs into a chaos.   

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #50 on: November 13, 2011, 01:37:09 AM »
Hi Kent,

ConsoleC.inc has no errors with the last Oxygen posting (about 6 hous ago) . Have you added more to it recently?

I regularly use the version included in the Oxygen /projects section, for testing :)

Charles
« Last Edit: November 13, 2011, 02:04:14 AM by Charles Pegge »

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #51 on: November 14, 2011, 01:59:10 PM »
Thanks for the reply Charles, I probably downloaded an older version. Sorry about that.

efgee

  • Guest
Re: Can't get my console class to work
« Reply #52 on: November 14, 2011, 04:47:07 PM »
My own console class I had working isn't working anymore either...

Anyway, found one in "OxygenBasic\projects\GLWindow\" and seems to be yours  :)

But it looks like that one is broken as well as Oxygen only accepts constants as array-index:

Code: [Select]
        method GetChrsAt( sys aX, sys aY, sys aNumCharsToRead ) as string
            sys numRead
            char charsRead[aNumCharsToRead]     ' <- ERROR
            COORD crd => ( aX, aY )
            ReadConsoleOutputCharacterA( mhOut, charsRead, aNumCharsToRead, crd, numRead )
            return charsRead
        end method

Oxygen doesn't accept function parameters as array-index anymore ?

Hmm...

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #53 on: November 15, 2011, 05:35:40 AM »
Hi Frank

Oxygen only supports static array declarations, so you have to use a constant to specify the number of elements, not a variable. The memory space for the array is determined at compile time.

This issue escaped detection before, and worked due to a large spurious index value being used.

This is how it now looks in projects/Console/ConsoleC.inc

Code: [Select]
       method GetChrsAt( sys aX, sys aY, sys aNumCharsToRead ) as string
            sys numRead
            char charsRead[256]
            COORD crd => ( aX, aY )
            ReadConsoleOutputCharacterA( mhOut, charsRead, aNumCharsToRead, crd, numRead )
            return charsRead
        end method

Charles

« Last Edit: November 15, 2011, 05:50:23 AM by Charles Pegge »

efgee

  • Guest
Re: Can't get my console class to work
« Reply #54 on: November 15, 2011, 08:50:59 AM »
Thanks Charles,
256 chars should be sufficient anyway...

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #55 on: November 15, 2011, 11:33:09 AM »
That is the most efficient solution.

If you need a flexible buffer, or one that is large then use a string:

function bar(sys MaxBytes) as string
string Buf=nuls MaxBytes
sys BytesRead
foo buf,MaxBytes,BytesRead
return left Buf,BytesRead
end function


Code: OxygenBasic
  1.  
  2. function foo(char*z, sys MaxBytes,*BytesRead)
  3. z=left "okay",MaxBytes
  4. BytesRead=len z
  5. end function
  6.  
  7. function bar(sys MaxBytes) as string
  8. string Buf=nuls MaxBytes
  9. sys BytesRead
  10. foo buf,MaxBytes,BytesRead
  11. return left Buf,BytesRead
  12. end function
  13.  
  14.  
  15. sys BytesToRead=1000
  16. print bar (BytesToRead)
  17.  
  18.  

Charles
« Last Edit: November 15, 2011, 11:35:35 AM by Charles Pegge »