Virtual Events

   

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 26.  Binding Commands to Events


A virtual event corresponds to one or more event sequences. When any of the event sequences occurs, then the virtual event occurs. The next example shows the default virtual events for each platform:

Example 26-4 Virtual events for cut, copy, and paste.
 switch $tcl_platform(platform) {     "unix" {       event add <<Cut>> <Control-Key-x> <Key-F20>       event add <<Copy>> <Control-Key-c> <Key-F16>       event add <<Paste>> <Control-Key-v> <Key-F18>    }    "windows" {       event add <<Cut>> <Control-Key-x> <Shift-Key-Delete>       event add <<Copy>> <Control-Key-c> <Control-Key-Insert>       event add <<Paste>> <Control-Key-v> <Shift-Key-Insert>    }    "macintosh" {       event add <<Cut>> <Control-Key-x> <Key-F2>       event add <<Copy>> <Control-Key-c> <Key-F3>       event add <<Paste>> <Control-Key-v> <Key-F4>    } } 

You can define more than one physical event that maps to the same virtual event:

 event add <<Cancel>> <Control-c> <Escape> <Command-.> 

With this definition any of the physical events will trigger a <<Cancel>>. This would be convenient if the same user commonly used your application on different platforms. However, it is also possible that the physical bindings on different platforms overlap in conflicting ways.

By default, virtual event definitions add to existing definitions for the same virtual event. The previous command could be replaced with these three:

 event add <<Cancel>> <Control-c> event add <<Cancel>> <Escape> event add <<Cancel>> <Command-.> 

The event command is summarized in Table 26-3.

Table 26-3. The event command.
event add virt phys1 phy2 ...Adds a mapping from one or more physical events to virtual event virt.
event delete virtDeletes virtual event virt.
event infoReturns the defined virtual events.
event info virtReturns the physical events that map to virt.
event generate win event ?opt val? ...Generates event for window win. The options are listed in Table 26-4.


       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net