Gentee Programming Language > Documentation > Tutorial Download documentation

Lesson 10

This lesson will be useful for those users who would like to know about key pressing emulation.

Example 1

Launch an editor, then paste a text from the clipboard, print a text in the editor, copy the whole text to the clipboard and close the editor without saving it to a file. The operations listed above will be performed automatically.

First, we specify the following three libraries that will be used in the example: threads, data input, clipboard operations. You may not use threads, however it is a good opportunity for you to get to know about them. A thread is a function operated at the same time as the main process. I consider that the term "thread" is defined in a simple way,nevertheless I tried to make it easy to understand.

include 
{
   $"..\lib\input.ge"
   $"..\lib\thread.ge"
   $"..\lib\clipboard.ge"
}

Well, let's get started with the main function.

func lesson10<main>
{
   thread   mythread
   str      data
   
   mythread.create( &notepad, 700 )
   clipboard_settext( "Hello!\l" )
   
   process( "notepad.exe", 0->str, &ret )

   congetch("\(clipboard_gettext( data ))\n=============\nPress any key...")
}

We declare the variable of thread type and create the thread used for key pressing emulation. In the parameter the delay time between operations will be specified in milliseconds. If the delay time is not set, the program will be terminated rapidly and you cannot have a chance to observe operations thoroughly.

Then we copy the word Hello! to the clipboard, launch the editor Notepad and wait for the program to be terminated. If you want the process to be launched but don't want to wait for its termination, enter zero in the third parameter of the process function. When an editor window has been closed, we will receive the text from the clipboard and output it to a console.

Let's jump to the thread function notepad.

func uint notepad( uint param )
{
   ...

First, it is necessary to set a half a second delay time for Notepad launching. Within this lesson, all sleep functions will be skipped. Using the sendvkey function, the shortcut keys Shift-Insert paste a text from the clipboard.

   sleep( 500 )
   sendvkey( $VK_INSERT, $SVK_SHIFT )

When the date and time are obtained, they will be set in the editor with help of the sendstr function.

   sleep( param )
   dt.gettime()   
   getdatetime( dt, date, time )
   sendstr( "Date: \(date)\lTime: \(time)" )

We highlight the whole text with the shortcut keys Ctrl-A and press Ctrl-Insert for copying it to the clipboard.

   sleep( 3 * param )
   sendvkey( 'A', $SVK_CONTROL )  
   sendvkey( $VK_INSERT, $SVK_CONTROL )

The last thing we should do is to close the program by pressing Alt-F4 without saving data to the file. The shortcut keys Alt-F4 are usually used to close a window, therefore while the program executes, do not switch to any other windows, otherwise the current window will be closed.

   sleep( param )
   sendvkey( $VK_F4, $SVK_ALT )  
   sleep( param )
   sendvkey( $VK_RIGHT, 0 )  
   sleep( param )
   sendvkey( $VK_RETURN, 0 )
   return 1
}

You have already noticed that this program is rather compact, however it performs the task completely. If you would like to deal with any automatization, you could always have an opportunity to modify this example. Therefore, there is no need for you to do some extra exercises.


 Copyright © 2004-2006 Gentee Inc. All rights reserved.