zsh-users
 help / color / mirror / code / Atom feed
* Bindkey + PageUp/PageDown keys
@ 2000-12-11 12:14 Oliver Grimm
  2000-12-12  1:38 ` Geoff Wing
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Grimm @ 2000-12-11 12:14 UTC (permalink / raw)
  To: zsh-users


I'd like to assign some operations like, e.g.,  vi-beginning-of-line 
to the special keys PageUp, PageDown, Home etc.
But I don't seem to understand the correct behaviour of the
bindkey command. Whereas I got with 'bindkey -s a b' the expected
behaviour, I don't know how to apply this to these special keys.
In xterm, they are called 'Prior', 'Next', etc. but how do I use
this with bindkey ?

Thanks for help,	Oliver.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bindkey + PageUp/PageDown keys
  2000-12-11 12:14 Bindkey + PageUp/PageDown keys Oliver Grimm
@ 2000-12-12  1:38 ` Geoff Wing
  2000-12-13  5:03   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Geoff Wing @ 2000-12-12  1:38 UTC (permalink / raw)
  To: zsh-users

Oliver Grimm <grimm@particle.phys.ethz.ch> typed:
:I'd like to assign some operations like, e.g.,  vi-beginning-of-line 
:to the special keys PageUp, PageDown, Home etc.
:But I don't seem to understand the correct behaviour of the
:bindkey command. Whereas I got with 'bindkey -s a b' the expected
:behaviour, I don't know how to apply this to these special keys.
:In xterm, they are called 'Prior', 'Next', etc. but how do I use
:this with bindkey ?

Your terminal emulator (xterm) will translate the Prior (PageUp)
and Next (PageDown) keys into a character sequence - usually an
escape sequence (i.e. the first character in the sequence is an
escape character).  Do a normal bindkey command however you may
need to make zsh quote the first character.

% bindkey '<CTRL-V><PageUp>' vi-beginning-of-line

and you should see something like:

% bindkey '^[[5~' vi-beginning-of-line

You don't want the -s flag to bindkey here since you want to
execute a command.

Regards,
-- 
Geoff Wing : <gcw@pobox.com>
Rxvt Stuff : <gcw@rxvt.org>
Zsh Stuff  : <gcw@zsh.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bindkey + PageUp/PageDown keys
  2000-12-12  1:38 ` Geoff Wing
@ 2000-12-13  5:03   ` Bart Schaefer
  2000-12-13  6:22     ` Dan Nelson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2000-12-13  5:03 UTC (permalink / raw)
  To: zsh-users

On Dec 12,  1:38am, Geoff Wing wrote:
} Subject: Re: Bindkey + PageUp/PageDown keys
}
} Oliver Grimm <grimm@particle.phys.ethz.ch> typed:
} :In xterm, they are called 'Prior', 'Next', etc. but how do I use
} :this with bindkey ?
} 
} Your terminal emulator (xterm) will translate the Prior (PageUp)
} and Next (PageDown) keys into a character sequence - usually an
} escape sequence (i.e. the first character in the sequence is an
} escape character).

Here's a little something I cobbled together.  I've called it "zkbd".
It works better as a shell script than as a function, so I suppose if
it goes into the distribution it should go under the top-level Misc/
directory rather than in Functions/Misc/.

Run "zkbd" and it'll ask you to press a bunch of function and movement
keys.  It records those sequences in ~/.zkbd/$TERM in the associative
array $key (so this requires 3.1.9).

I realize that naming the file after $TERM is not quite accurate because
e.g. one can use an xterm with with just about any kind of keyboard.  On
the other hand, the same keyboard can generate different sequences in
different terminal emulators.  If someone has a better idea for the file
naming convention, I'd be happy to hear it.

Further, if somebody has one of those Sun keyboards with the 24 extra
function keys in left and right banks, and wants to fix this up to work
with that as well -- e.g., check that $DISPLAY or $TTY refers to the
console, that the hardware is Sun, et cetera, and prompt for the extra
keys when so -- that'd be cool too.

---- 8< ---- cut here ---- 8< ----
#! /bin/zsh -f

emulate -RL zsh
local zkbd term key seq

zkbd=${ZDOTDIR:-$HOME}/.zkbd
[[ -d $zkbd ]] || mkdir $zkbd || return 1

print 'typeset -A key\n' > $zkbd/$TERM.tmp || return 1
trap "command rm -f $zkbd/$TERM.tmp" 0 1 2

read term"?Enter current terminal type: [$TERM] "
[[ -n $term ]] && TERM=$term

cat <<EOF

You will now be asked to press in turn each of the 12 function keys, plus
the 6 common keypad keys found on typical PC keyboards, plus the 4 arrow
keys.  If you do not press a key within 10 seconds, key reading will
abort.  If your keyboard does not have the requested key, press Space to
skip to the next key.

Do not type ahead!  Wait at least one second after pressing each key for
zsh to read the entire sequence and prompt for the next key.  If a key
sequence does not echo within 2 seconds after you press it, that key may
not be sending any sequence at all.  In this case zsh is not able to make
use of that key.  Press Space to skip to the next key.

EOF

getseq () {
    trap 'stty -raw' 0 1 2
    stty raw
    local k='' seq='' i
    for ((i=5; i>0; --i))
    do
	read -t -k 1 k && break
	sleep 1
    done
    [[ -n $k ]] || return 1
    [[ $k = $'\012' || $k = $'\015' || $k = ' ' ]] && return 0
    seq=$k
    while read -t -k 1 k
    do
       seq=$seq$k 
    done
    print -R ${(V)seq}
}

exec 3>/dev/tty

for key in F{1..12} Insert Delete Home End PageUp PageDown Up Left Down Right
do
    print -u3 -Rn "Press $key: "
    seq="$(getseq)" || return 1
    print "key{$key}=${(q)seq}"
    print -u3
done >> $zkbd/$TERM.tmp

command mv $zkbd/$TERM.tmp $zkbd/$TERM

cat <<EOF

Parameter assignments for the keys you typed have been written to the file:
$zkbd/$TERM

You may read this file into ${ZDOTDIR:-$HOME}/.zshrc or another startup
file with the "source" or "." commands, then reference the \$key parameter
in bindkey commands like this:

    bindkey "\$key{Right}" forward-char
    bindkey "\$key{Left}" backward-char

EOF
---- 8< ---- cut here ---- 8< ----

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bindkey + PageUp/PageDown keys
  2000-12-13  5:03   ` Bart Schaefer
@ 2000-12-13  6:22     ` Dan Nelson
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Nelson @ 2000-12-13  6:22 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

In the last episode (Dec 13), Bart Schaefer said:
> On Dec 12,  1:38am, Geoff Wing wrote:
> } Subject: Re: Bindkey + PageUp/PageDown keys
> }
> } Oliver Grimm <grimm@particle.phys.ethz.ch> typed:
> } :In xterm, they are called 'Prior', 'Next', etc. but how do I use
> } :this with bindkey ?
> } 
> } Your terminal emulator (xterm) will translate the Prior (PageUp)
> } and Next (PageDown) keys into a character sequence - usually an
> } escape sequence (i.e. the first character in the sequence is an
> } escape character).
> 
> I realize that naming the file after $TERM is not quite accurate
> because e.g. one can use an xterm with with just about any kind of
> keyboard.  On the other hand, the same keyboard can generate
> different sequences in different terminal emulators.  If someone has
> a better idea for the file naming convention, I'd be happy to hear
> it.

It should be perfectly accurate, since TERM specifies not only output
escape sequences but input sequences as well; that's what all the
capabilities starting with k are.  If you have two terminal emulators
that send different ESC sequences for different keys, they should have
different TERM types (or you should submit a bug report to the author
of the one that's sending incorrect codes).

I use the following function in /etc/zshrc.  It's a wrapper around
bindkey that takes an extra argument - the termcap code to bind an
action to.  $2 is only used if there is no entry for that code.  I've
had this in my zshrc for so long I honestly have no idea what zsh's
default settings are for the keys I replace :)

# usage: bindtc <cap> <fallback> <zsh-command>
bindtc () 
{
	local keyval=$(echotc "$1" 2>&-)
	bindkey "${keyval:-$2}" "$3"
}

# Let backtab cycle through completions in reverse
bindtc bt "^[[Z" reverse-menu-complete

# Bindings for PGUP, PGDN, HOME, END
bindtc kP "^[[I" history-beginning-search-backward
bindtc kN "^[[G" history-beginning-search-forward
bindtc kh "^[[H" beginning-of-line
bindtc kH "^[[F" end-of-line

# Bindings for UP, DOWN, LEFT, RIGHT
bindtc ku "^[[A" up-line-or-history
bindtc kd "^[[B" down-line-or-history
bindtc kr "^[[C" forward-char
bindtc kl "^[[D" backward-char

-- 
	Dan Nelson
	dnelson@emsphone.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-12-13  6:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-11 12:14 Bindkey + PageUp/PageDown keys Oliver Grimm
2000-12-12  1:38 ` Geoff Wing
2000-12-13  5:03   ` Bart Schaefer
2000-12-13  6:22     ` Dan Nelson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).