Version 1 of dead keys for accents

Updated 2003-11-11 19:27:18

Entering text with accented characters can be tedious, because normally under X (Linux) the keyboard uses so-called 'nodeadkeys'. To be able to enter as many accented characters as possible, I developed a little package called 'deadkeys'.

A global variable 'switch' is used to show whether the state of the keyboard has changed, meaning that one of the dead keys has been pressed. You could use this as a textvariable for a label so that its content shows.

This package has not been tested on any other environment than Linux + X with a German keyboard.

  package provide deadkeys 1.0

  ### accented keys
  # list of all classes where chars are applied
  set classes [list Text Entry]

  foreach class $classes {
    bind $class <KeyPress-acute> {
      if {$switch == ""} {
        set switch "acute"
      } else {
        set switch ""
      } ;# if
      break
    } ;# bind

    bind $class <KeyPress-grave> {
    if {$switch == ""} {
        set switch "grave"
      } else {
        set switch ""
      } ;# if
      break
    } ;# bind

    bind $class <KeyPress-asciicircum> {
      if {$switch == ""} {
        set switch "circum"
      } else {
        set switch ""
      } ;# if
      break
    } ;# bind

    bind $class <KeyPress-degree> {
      if {$switch == ""} {
        set switch "degree"
      } else {
        set switch ""
      } ;# if
      break
    } ;# bind
    bind $class <KeyPress-plus> {
      if {"%A" == "~"} {
        if {$switch == ""} {
          set switch "tilde"
        } else {
          set switch ""
        } ;# if
      } ;# if
      break
    } ;# bind

    bind $class <Key> {
      if {$switch != "" && "%A" != "{}"} {
        set ch   "%A"
        set i_ch "%A"
        if {$switch == "acute"} {
          switch %A {
           " " {set i_ch "´"}
            a  {set i_ch "á"}
            A  {set i_ch "Á"}
            e  {set i_ch "é"}
            E  {set i_ch "É"}
            i  {set i_ch "í"}
            I  {set i_ch "Í"}
            o  {set i_ch "ó"}
            O  {set i_ch "Ó"}
            u  {set i_ch "ú"}
            U  {set i_ch "Ú"}
            c  {set i_ch "?"}
            C  {set i_ch "?"}
            n  {set i_ch "?"}
            N  {set i_ch "?"}
            l  {set i_ch "?"}
            L  {set i_ch "?"}
            s  {set i_ch "?"}
            S  {set i_ch "?"}
            r  {set i_ch "?"}
            R  {set i_ch "?"}
            z  {set i_ch "\u017A"}
            Z  {set i_ch "\u0179"}
          } ;# switch
        } elseif {$switch == "grave"} {
          switch %A {
           " " {set i_ch "`"}
            a  {set i_ch "à"}
            A  {set i_ch "À"}
            e  {set i_ch "è"}
            E  {set i_ch "È"}
            i  {set i_ch "ì"}
            I  {set i_ch "Ì"}
            o  {set i_ch "ò"}
            O  {set i_ch "Ò"}
            u  {set i_ch "ù"}
            U  {set i_ch "Ù"}
          } ;# switch
        } elseif {$switch == "circum"} {
          switch %A {
           " " {set i_ch "^"}
            a  {set i_ch "â"}
            A  {set i_ch "��"}
            e  {set i_ch "ê"}
            E  {set i_ch "Ê"}
            i  {set i_ch "î"}
            I  {set i_ch "Î"}
            o  {set i_ch "ô"}
            O  {set i_ch "Ô"}
            u  {set i_ch "û"}
            U  {set i_ch "Û"}
            w  {set i_ch "\u0175"}
            W  {set i_ch "\u0174"}
            z  {set i_ch "\u0177"}
            Z  {set i_ch "\u0176"}
            c  {set i_ch "\u00E7"}
            C  {set i_ch "\u00C7"}
            s  {set i_ch "\u015F"}
            S  {set i_ch "\u015E"}
            g  {set i_ch "\u011F"}
            G  {set i_ch "\u011E"}
          } ;# switch
        } elseif {$switch == "degree"} {
          switch %A {
           " " {set i_ch "°"}
            a  {set i_ch "å"}
            A  {set i_ch "Å"}
            e  {set i_ch ""}
            E  {set i_ch ""}
            i  {set i_ch "\u0131"}
            I  {set i_ch "\u0130"}
            o  {set i_ch ""}
            O  {set i_ch ""}
            u  {set i_ch "\u016F"}
            U  {set i_ch "\u016E"}
          } ;# switch
        } elseif {$switch == "tilde"} {
          switch %A {
           " " {set i_ch "~"}
            a  {set i_ch "ã"}
            A  {set i_ch "��"}
            e  {set i_ch ""}
            E  {set i_ch ""}
            i  {set i_ch "?"}
            I  {set i_ch "?"}
            o  {set i_ch "õ"}
            O  {set i_ch "Õ"}
            u  {set i_ch "\u0169"}
            U  {set i_ch "\u0168"}
            n  {set i_ch "ñ"}
            N  {set i_ch "Ñ"}
          } ;# switch
        } ;# if
        if {$ch == " " || $ch >= {a} && $ch <= {z} || $ch >= {A} && $ch <= {Z}} {
          %W insert insert "$i_ch"
          set switch ""
          break
        } else {
          tk_messageBox -message "out of area"
        } ;# if
      } else {
        %W insert insert %A
      } ;# if
    } ;# bind
  } ;# foreach class

I added some bindings which can be very helpful especially for Turkish users. Using the ring accent on i gives a dotless i, ring accent on I gives a capital I with a dot, using the ring accent on a g/G gives the same character in its soft variation (yumusak g), using a circumflex on s/S gives the same character with a cedille unterneath.

Hope this proves to be helpful.

HolgerJ