[mjk] 2005-10-17: Consio is a small console library for Windows. I created it, so I can make small textbased menus and catch single keystrokes and not always use Tk for creating user interfaces. It's also handy for asking passwords from user and not echo them back to the screen. The library is written in C and has been compiled with Cygwin tools under Cygwin environment using MinGW libraries and headers (so there are no dependencies to the Cygwin). The source code and binary are available here: [http://www.iki.fi/mjk/files/Consio.zip]. The whole package is released under the MIT license. Here's a screenshot: [http://www.iki.fi/mjk/img/tcl/Consio.jpg] The library is pretty skimpy (well, it's version 0.2 at the moment, so don't expect too much), but it already implements the following commands: Consio::clrscr Clears screen (console buffer). Consio::gotoxy x y Sets a new cursor location to (x;y). Consio::wherex Returns the X position of the cursor in the console buffer. Consio::wherey Returns the Y position of the cursor in the console buffer. Consio::bufferwidth Returns the width of the console buffer. Consio::bufferheight Returns the height of the console buffer. Consio::getch Waits for single key press. Consio::getche Waits for single key press and echoes it back to the console. Consio::putch chr Inserts a character to the cursor location. Consio::kbhit checks if there are any keystokes waiting in the input buffer. This function doesn't block or remove anything from the buffer. The function will return 1 if there are keystrokes waiting in the input buffer. Otherwise returns 0. Consio::textattr foreground background Sets foreground and background color. Available color attributes for both foreground and background color are: black blue green cyan red magenta brown lightgray darkgray lightblue lightgreen lightcyan lightred lightmagenta yellow white Consio::cputs ?-nonewline? string Prints string to standard output. If -nonewline is specified, then then the newline will not be printed at the end of the line. Consio::cgets Reads keystrokes from the console until Enter key is pressed. Linefeed or newline characters are not included in the result. Consio::cgetse Reads keystrokes from the console and echoes them back until the Enter key is pressed. Linefeed or newline characters are not included in the results. Consio::getchex Extended getch. Getch is unable to return a meaningful code for all keys. For example, there is no easy way to return arrow keys as a single character. Getchex works like getch except it will return key presses as an integer value. This way it's possible to receive a code from all keys, including shifts, function keys, arrows etc. The code is device-independent and defined by Windows. ---- Few words about the future goals: My intention is to provide a library with all essential console functions included. In addition, I'm planning to create a Tcl package on top of the library, which would provide some basic dialogs and menus (like a utility program called "dialog" does under Linux). ---- At the moment, this library has been tested only under Windows XP. All feedback is welcome and I would appreciate it greatly if people would tell me, how the library works under different flavors of Windows. The feedback can be appended to this page or sent directly to me (e-mail address is included in the package). [jmn] 2005-10-18 Nice work - thanks for sharing. It works fine on my old Windows NT & 2000 server boxes. A consequence of course of using ReadConsole instead of lower level Console API functions such as ReadConsoleInput; is that Consio as it stands doesn't catch certain keys such as arrows, delete, end etc.. Perhaps 'press any key' in the demo should be qualified a little - otherwise the old joke about lusers hunting for the key marked 'any' just isn't as funny ;) [LES]: this is very nice, and seems to work in my Windows 98. I couldn't make '''getch''' and '''getche''' work, but I suspect I just did something wrong. [mjk] 2005-10-20: [jmn], the "any key" issue will be fixed in next version, so no stupid user will be lost in the quest for finding the "any key" :) [LES], I'm afraid that there is a small possibility that (at least at this point) this library will not work flawlessly under Windows 9x. Microsoft documentation claims that all functions I'm using are supported under older operating systems, but I'm not sure, if I can trust that. But I'm going to study this issue further at some point. [mjk] 2005-10-20: Well, there is now the version 0.2 available and it among other things has an extended version of the getch command called "getchex", which will capture any keypress from the console and return a key code. ---- Here's a conversation about this page, from the [TkChat] channel, on 2006-03-14. [willdye] is there possible to write "raw" to console? windows console supports command "prompt" which can allows ASCII and i wanna try to use this tclguy ?? kbk mAcZ - What are you trying to do, in more general terms. i wanna use ascii chars in windows console, to use color for text aku I would say that you want ANSI sequences, not ASCII kbk Windows console - the black thing from a command line application, or the Wish console? The answers are different for the two. the black thing * kbk tries to remember what's to be done for the Windows console - suspects that the answer is "it's not easy." tclguy that requires C API stuff IIRC, not just terminal control codes like a unix tty kbk tclguy - ISTR there's a way to jigger a Command Prompt to take ANSI escape sequences, but don't remember what it is. (And I don't remember whether it takes C code that we don't have) kbk console I/O extension - http://wiki.tcl.tk/14850 AH! perfect, big thanks * kbk bows. :) ---- [[ [Category Package] ]] [[ [Category Text Screen] ]]