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

Table of contents -> Chapter 14 - Miscellaneous Functions


The next topic is the description for the use of the following TEIMSI predefined functions:

1)- reghotkey(keys,address_of_procedure)

2)- regtimer(integer_time,integer_pointer)

3)- seterrorlevel(number)

4)- waitevent()

5)- openapp(path)

6)- fn_at_long(integer_pointer)

7)- waitfor(milliseconds_amount)




reghotkey

The "reghotkey" function associates a key combination to a TEIMSI function. Then, when you press such key combination the function is called (which does not receive parameters as TEIMSI Variables).

Two parameters are received where the first describes the special keys and the second is the procedure name preceded by the "@" character, for example: @task1 ("task1" is the TEIMSI declared function).

Also can detach a combination of keys previously associated with the same function, for which the second parameter must be 0 (integer zero). The default "waitevent()" function is used for entering listening state, it means that it stops the flow of execution of code the program but continues to flow if the associated procedure returns the "true" boolean in instead of "false".


Syntax
reghotkey(keys,address_of_procedure)
 

Parameters
keys
"keys" represents a string variable that describes the combination of keys to use, on its content the first three characters describe whether or not to use Shift, Control and Alt : to use Shift + Alt will "s-a" (the hyphen indicates that the Control key is not used), to use Ctrl + Alt it should be "-ca". Then after these three characters comes a dot (".") and an additional key on the keyboard is indicated by a string (not case sensitive) of which are in the following list of words (separated by a comma): back, clear, delete, down, end, escape, home, insert, lbutton, mbutton, rbutton, left, pause, pgdn, pgup, print, return, right, shift, snapshot, space, tab, up, numpad0, numpad1, numpad2, numpad3, numpad4, numpad5, numpad6, numpad7, numpad8, numpad9, multiply, add, separator, subtract, decimal, divide, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, numlock, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
 


Returned value
boolean
TEIMSI variable with a data type of boolean (true or false) that indicates the result of the function. If "false" is returned, functions "err_number" and "err_description" can be used to get the error's description.
 

Example:



//	The following example shows a program that register the Ctrl+Alt+P keys, then waits for the combination key is made to exit.


	function event(){
		alert("You pressed Ctrl+Alt+P")
		return true;	//	By returning "true", the "waitevent" function stops waiting for events.
	}
	//	Successively, it associates a combination to a procedure.

	var error=reghotkey("-ca.p",@event)
	if(error==false){
		alert("An error was raised when registering keys Ctrl+Alt+P, description: "+_nl+"	"+err_description(err_number()))
		sys.quit()
	}else{
		alert("Press Ctrl+Alt+P to exit!")
	}
	waitevent()

	reghotkey("-ca.p",0)		//	Detaches the keys Ctrl+Alt+P.

	//	These instructions show you an example of what happens when the key is already associated by another application (Ctrl+Alt+Delete is an operating system command).

	var error=reghotkey("-ca.delete",@event)
	if(error==false){
		alert("An error was raised when registering keys Ctrl+Alt+Delete, description: "+_nl+"	"+err_description(err_number()))
	}
	sys.quit()			//	Finishes the application.



See also <<err_number>>, <<err_description>>, <<waitevent>>, <<regtimer>>


Go to top

regtimer

The "regtimer" function registers a "timer" to a procedure. A "timer" calls every few milliseconds (1 millisecond = 0.001 seconds) to a procedure. The procedure or function TEIMSI should not receive parameters. The default "waitevent()" function is used for entering listening state "timers", it means that stops the flow of execution of code the program but continues to flow if the associated procedure returns the boolean "true "instead of" false ".


Syntax
1- regtimer(integer_milliseconds,@procedure)
 
2- regtimer(handle_regtimer,0)
 

Parameters
Integer parameter 1
TEIMSI variable with data type of a 32 bits integer number. If you want to register a "timer" to a function this parameter indicates the milliseconds. If you want to drop a "timer" this must be worth the integer (handler) returned by the same "regtimer" function on a previous call.
 
Integer parameter 2
TEIMSI variable with data type of a 32 bits integer number. If you want to register a "timer" to a function this parameter indicates the procedure preceded by "@". If you want to drop a "timer" this must be worth the integer 0 (zero).
 

Returned value
handle/boolean
If a "timer" is registered, returned value is a TEIMSI variable with data type of a 32 bits integer number that contains the "handle" (it can be used for a further disassociation). If a "timer" is dropped, the returned value is a boolean that indicates the result of the function.
 

Example:



	alert("Wait two seconds!")

	var timerh = regtimer(2000, @timer1);

	waitevent();

	alert("Will exit now!")

	function timer1(){
		var resultf = regtimer(timerh, 0);
		alert("Timer1 in action!")
		return true;
	}


See also <<reghotkey>>, <<waitevent>>


Go to top

seterrorlevel

The "seterrorlevel" function sets the value of the "errorlevel" integer used after completing the application.


Syntax
seterrorlevel(integer_number)
 

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

Returned value
boolean
TEIMSI variable with a data type of boolean (true or false) that indicates the result of the function.
 

Example:



//	The following example shows an utility of "seterrorlevel".
//	Edit with the TEIMSI editor a file and name it "errorlevel.tsi", put the following line and then press F5.

	seterrorlevel(2)

//	Now edit a file called "test.bat" in the same folder as the .exe file, put the following and run it the .bat

	@echo off
	call errorlevel.exe
	if errorlevel 2 goto et2
	
	echo "Error level 0"
	pause
	exit
	
	:et2
	echo "Error level 2"
	pause
	exit

//	As you will see appears the string "Error level 2".
	


See also <<openapp>>


Go to top

waitevent

The "waitevent" function stops the flow of the program until the call of a "timer" (registered with the "regtimer" function) or combination of keys (registered with the "reghotkey" function) holds.


Syntax
waitevent()
 

Parameters
(none)
 

Returned value
(none)
 

See also <<regtimer>>, <<reghotkey>>


Go to top

openapp

The "openapp" function run a program or document in the file system to open the file the operating system (or corresponding application associated with the file type). Get a parameter that is the path to the document or program, if it's a program you can specify its input command line: to do it the path must be followed by the character "<" and then the command line.


Syntax
openapp(path)
 

Parameters
path
TEIMSI variable with a data type of string. It indicates the location to the file.
 

Returned value
boolean
TEIMSI variable with a data type of boolean (true or false) that indicates the result of the function.
 

Example:



//	Edit with TEIMSI Editor a file called "program.tsi", put on it the following line and then press F5.

	alert(cmdline())

//	This shows message with the program's path.

//	Now edit with TEIMSI Editor a file called "caller.tsi", put on it the following lines, then press F5.

	if(fileexists("program.exe")){
		openapp("program.exe<Hello!")		//	This runs the file "program.exe" if it exists.
	}

//	As you will see, a message with the path appears to the file "program.exe" and the command line (which in this case is "Hello!").



See also <<cmdline>>


Go to top

fn_at_long

The "fn_at_long" function calls to a procedure whose location in the code section is specified with an integer TEIMSI variable.


Syntax
fn_at_long(integer_number)
 

Parameters
integer_number
TEIMSI variable with data type of a 32 bits integer number containing the pointer to the memory address of the procedure.
 

Returned value
variable
Returned variable by the called procedure.
 

Example:


	var position=@example

	var num=fn_at_long(position)
	
	alert("380 + 2 = "+ num)
	
	function example(){
		alert("Hi!")
		return 382
	}


See also <<regtimer>>


Go to top

waitfor

The "waitfor" function expects the specified number of milliseconds and then continues the execution of the program.


Syntax
waitfor(integer_number)
 

Parameters
integer_number
TEIMSI variable with data type of a 32 bits integer number. It indicates the time in milliseconds.
 

Returned value
boolean "true"
TEIMSI variable with a data type of boolean.
 

Example:


	// The following program uses "waitfor".

	alert("Wait 1,5 seconds")
	waitfor(1500)
	alert("Done!")


See also <<regtimer>>


Go to top