I'm not familiar with autokey, but this looks doable. Use
Keyboard.press_key to send a key press event and
Keyboard.release_key to send a key release event. To remember which one to send, you can use
Alternatively, you can use xdotool to inject input events into a window and
xprop to attach data to a window. Run the following shell command (untested) to send alternate press/release events to the active window.
case $(xprop -id "$window_id" -f key_e_is_down 32c -notype key_e_is_down) in
*1) key_command=keydown; new_state=0;;
*) key_command=keyup; new_state=1;;
xdotool "$key_command" "e"
xprop -id "$window_id" -f key_e_is_down 32c -set key_e_is_down "$new_state"
If you want to bind this action to a key, but to have the key active only in one window, I'm not sure if Autokey can help you. The easiest way to do that is from the window manager, but most window managers can't do it. I use sawfish as my window manager, which can do this without any external tool.
(define (toggle-e w)
(let ((down (window-get w 'key-e-is-down)))
(synthesize-event (if down "Release+e" "e") w)
(window-put w 'key-e-is-down (not down))))
(define xyz-window-map (make-keymap))
(bind-keys xyz-window-map "e" toggle-e)
(add-window-matcher 'WM_CLASS "^Xyz/" `((keymap . ,xyz-window-map)))