TEIMSI
Developer's platform of programming text codes
Home|Utilities|Forum|Documentation

Table of contents -> Chapter 15 - Functions for the console modality programs


The functions described in this chapter are important for console mode executable programs, to give this mode a program will proceed (as an example) as follows:

1- Create the main project's file, for example "console.tsi" and open it with the TEIMSI editor and compiler.

2- Write in the file the next 4 lines:

		console_cls()
		console_locate(10,10)
		console_print("Hi world!")
		console_waitkey()

3- Press the key F4 (or the Compile's menu "Save and only compile TEIMSI script").

4- Edit the file named "base_exe.asm" inside the "console_asm_files" folder, locate and replace the following lines:


			format PE GUI 4.0
			;format PE console

Comment the first and Un-comment the second.

			;format PE GUI 4.0
			format PE console

Locate the line:

			;	call console_start_p

Change to:

				call console_start_p

Now locate the line:

			;	call console_end_p

Change to:

				call console_end_p

5- Run the file create.bat

6- Now run the file console.exe located within the folder of the file console.tsi.

Remark: it should be required to make a copy of the file "base_exe.asm" once it is manually modified, because every time that is compiled the original TEIMSI script it will be replaced by the default file "base_exe.asm"..

Now we'll see the description of the following functions:

1)- console_cls()

2)- console_locate(x,y)

3)- console_print(str)

4)- console_println(str)

5)- console_println2(str)

6)- console_waitkey()

7)- console_waitkeyex()

8)- console_alert(x,y,str)

9)- console_inputstr(len)

Remark: The open source code that the functions run is within the file "cont_console.asm" at the folder "engine" with the TEIMSI Editor file program.




console_cls

The "console_cls" function clears the screen of the console.


Syntax
console_cls()
 

Parameters
(none)
 

Returned value
(none)
 

See also <<console_print>>


Go to top

console_locate

The "console_locate" function changes the position of the text cursor in the console.


Syntax
console_locate(x_column,y_row)
 

Parameters
x_column
TEIMSI variable with data type of a 32 bits integer number.
 
y_row
TEIMSI variable with data type of a 32 bits integer number.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	console_cls()
	for(var k=0;k<65;k++){
		console_locate(k,parseint(13+8*sin(k/5)))
		console_print("x")
	}
	console_print(_nl)
	console_print("Press any key.")
	console_waitkey()


See also <<console_cls>>, <<console_print>>, <<console_locate>>, <<console_waitkey>>


Go to top

console_print

The "console_print" function prints a text such it is on the console in the current cursor position.


Syntax
console_print(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
(none)
 

See also <<console_locate>>


Go to top

console_println

The "console_println" function prints a text followed by a new line (carriage return and line feed, chr(13)+chr(10)) on the console at the current cursor position.


Syntax
console_println(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
(none)
 

See also <<console_locate>>


Go to top

console_println2

The "console_println2" function prints a text followed by a return new line (chr(13)+chr(10)) and then a string that says "Press any key to continue ..." on console on the current cursor position. After printing the text waits until a key is pressed.


Syntax
console_println2(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

See also <<console_locate>>, <<console_alert>>


Go to top

console_waitkey

The "console_waitkey" function wait for any key to be pressed and returns an integer with the ASCII code of the pressed key.


Syntax
console_waitkey()
 

Parameters
(none)
 

Returned value
decimal_number
TEIMSI variable with data type of floating point number.
 

Example:



	while(true){
		var k=console_waitkey()
		console_println("Key pressed: " + k)
		if(k==27){break}				//	If the key is "Escape", exit from the loop.
	}


See also <<console_waitkeyex>>


Go to top

console_waitkeyex

The "console_waitkeyex" function wait until you press or release a key, returning a TEIMSI array with 4 integers; each item (integer) indicates some information about

el evento.


Syntax
var data_arr=console_waitkeyex()
 

Parameters
Returned value
array
Variable of an array data type, with four items of integer type.
 


	The first integer of the returned array indicates whether the key was pressed (value 1) or released (value 0).

	The second indicates the code of the key (key code) according to the following table that has the names of keys.

			back,8            | numpad2,98        | f12,123           | b,66              
			clear,12          | numpad3,99        | f13,124           | c,67              
			delete,46         | numpad4,100       | f14,125           | d,68              
			down,40           | numpad5,101       | f15,126           | e,69              
			end,35            | numpad6,102       | f16,127           | f,70              
			escape,27         | numpad7,103       | f17,128           | g,71              
			home,36           | numpad8,104       | f18,129           | h,72              
			insert,45         | numpad9,105       | f19,130           | i,73              
			lbutton,1         | multiply,106      | f20,131           | j,74              
			mbutton,4         | add,107           | f21,132           | k,75              
			rbutton,2         | separator,108     | f22,133           | l,76              
			left,37           | subtract,109      | f23,134           | m,77              
			pause,19          | decimal,110       | f24,135           | n,78              
			pgdn,34           | divide,111        | numlock,144       | o,79              
			pgup,33           | f1,112            | 0,48              | p,80              
			print,42          | f2,113            | 1,49              | q,81              
			return,13         | f3,114            | 2,50              | r,82              
			right,39          | f4,115            | 3,51              | s,83              
			shift,16          | f5,116            | 4,52              | t,84              
			snapshot,44       | f6,117            | 5,53              | u,85              
			space,32          | f7,118            | 6,54              | v,86              
			tab,9             | f8,119            | 7,55              | w,87              
			up,38             | f9,120            | 8,56              | x,88              
			numpad0,96        | f10,121           | 9,57              | y,89              
			numpad1,97        | f11,122           | a,65              | z,90              

		The third item (with index 2) in the array is an integer expressing the ASCII code of the character of the key pressed.  

		The fourth item (with index 3) called "integer_flags" is an integer That has the boolean flags through certain bits that indicate the state (pressed or not) of the "Shift", "Control," "Alt" and many more that are shown in the following the number that follows the special key has activated only the corresponding bit to that key (in the binary numerical system) see the shown example.
	
		(Special key)	(Integer that represents it with the bit activated).
	
			Shift		|	4096		= 0001000000000000y (number in binary system).
			Ctrl		|	2048		= 0000100000000000y
			Alt		|	512		= 0000001000000000y
			Caps Lock	|	32768		= 1000000000000000y
			Num Lock	|	8192		= 0010000000000000y
			Scroll Lock	|	16384		= 0100000000000000y
		
		The predefined constant variables: _waitkey_shift, _waitkey_ctrl, _waitkey_alt, _waitkey_bmayus (Caps Lock), _waitkey_bnum (Num Lock), _waitkey_bdesp (Scroll Lock); value the displayed integers in the previous table.
	
	Also the predefined constant variables: _waitkey_isdown, _waitkey_scancode, _waitkey_asciichar, _waitkey_ctrlkeystate; their value is the integers 0,1,2,3 respectively, and are used to indicate the array's indexes.
	

Example:



	if(_console_handle==0){
		alert("It is necessary to the program to be in console mode.!")
		sys.quit()
	}
	// _waitkey_ctrlkeystate=3
	// _waitkey_ctrl=2048

	var keydata=0
	while(true){
		console_cls()
		console_locate(5,5)
		if(keydata!=0){
			var theflags=keydata[_waitkey_ctrlkeystate]

			keydata[_waitkey_ctrlkeystate]=theflags + "="+strtohex(binstrpack(longpack(keydata[_waitkey_ctrlkeystate])))		// Show a binary representation of the integer with the flags.

			console_println(implode(_nl,keydata)+ _nl)		//	Show the integer items of the array.

			if( (theflags & _waitkey_ctrl) != 0){		//	Shows if the Control key is pressed.
				console_println2("You pressed the Control key!")
			}
		}
		var keydata=console_waitkeyex()
		if(keydata[_waitkey_scancode]==27){break}			//	Waits for the Esc key.
	}


See also <<console_waitkey>>


Go to top

console_alert

The "console_alert" function places the cursor in the (x,y) indicated position by the first two parameters and then performs the same task of "console_println2" function with the third.


Syntax
console_alert(x_column,y_row,string)
 

Parameters
x_column
TEIMSI variable with data type of a 32 bits integer number.
 
y_row
TEIMSI variable with data type of a 32 bits integer number.
 
string
TEIMSI variable with a data type of string.
 

Returned value
(none)
 

See also <<console_println2>>


Go to top

console_inputstr

The "console_inputstr" function allows the user to input a text (string) from the keyboard.


Syntax
console_inputstr(integer_number)
 

Parameters
integer_number
TEIMSI variable with data type of a 32 bits integer number. It's the maximum size of the buffer and input string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:


	console_print("Input a text: ")

	var intxt=console_inputstr(100)

	console_println2(_nl+"You entered: "+ intxt)



See also <<console_print>>, <<console_println2>>


Go to top