Version 20 of event

Updated 2010-10-24 07:14:57 by dkf
event add <<virtual>> sequence ?sequence ...?
event delete <<virtual>> ?sequence sequence ...?
event generate window event ?option value option value ...?
event info ?<<virtual>>?

http://purl.org/tcl/home/man/tcl8.5/TkCmd/event.htm

Tested to work on Windows:

 event generate . <Alt-F4> ;# sudden death, somehow like [exit]

However, other Alt-(initial) events don't work when called from event, only from the keyboard.


A small proc I wrote for something. It takes two argument, a window and a keysym (http://www.purl.org/tcl/home/man/tcl8.5/TkCmd/keysyms.htm ), and returns a two-element list. Assuming that some action is defined for the window, the first element is /what/ the binding is to, and the second is the command actually run. If someone wants to clean my explaination up a little after looking at the proc, please go ahead, it's not particularly coherent :) -- MG

  (%1) proc eventchk {w s} {
    set ret [list "" ""] ; set list [list "" ""]
    set tags [bindtags $w]
    while { $ret == $list && $tags != "" } {
            if { [bind [lindex $tags 0] $s] != "" } {
                 set ret [list [lindex $tags 0] [bind [lindex $tags 0] $s]]
               } else {
                 set tags [lrange $tags 1 end]
               }
          }
    return $ret;
  }
  (%2) text .t
  (%3) eventchk .t <Return>
  Text {
    tk::TextInsert %W \n
    if {[%W cget -autoseparators]} {%W edit separator}
  }
  (%4) bind .t <Return> {puts "You pressed return" ; break}
  (%5) eventchk .t <Return>
  .t {puts "You pressed return" ; break"}

MG uses this again on August 2nd 2005 and finds one small "bug" - if a keysym is bound to an event (ie, <Control-c> -> <<Copy>>), searching for <Control-c> won't find it. (Searching for <<Copy>> will, but since the point of this is to find where and why a binding fires, that's not too helpful.) I'm not sure of a way around that, apart from checking [bind $window] for all events, and checking all of those to see if they fire on the binding, though...


See also


Harold Macmillan (former UK prime minister, when asked what might most easily steer a government off course):

Events, dear boy, events.