Binding arrow keys in Tk

Anyone know how to bind arrow keys in Tk? The first bind call below does
what I want. The second doesn’t have any apparent effect. My window has
some buttons as well as a canvas, and the buttons have focus, but I
don’t bind arrows in the buttons (tried it, had no effect either).

works

$root.bind “period” do
$canvas.xview “scroll”, 1, "units"
end

#doesn’t work
$root.bind “rightarrow” do
$canvas.xview “scroll”, 1, "units"
end

Here’s a snippet from one of mine that works:

	# Keyboard and Button Bindings
	@doc.bind('Key-Tab')			{|e| keyTab(e)}
	@doc.bind('Key-Return')			{|e| keyTab(e)}
	#@doc.bind('Shift-Key-Tab')		{|e| keyLeftTab(e)} #Windows
	@doc.bind('Key-ISO_Left_Tab')	{|e| keyLeftTab(e)} #Linux

	@doc.bind('Key-Up')			{|e| keyUpArrow(e)}
	@doc.bind('Key-Down')			{|e| keyDownArrow(e)}

	@doc.bind('B1-ButtonRelease')	{|e| Button1Release(e)}

	@doc.bind('Control-Key-c')		{|e| clearCell(e)}
	@doc.bind('Control-Key-C')		{|e| clearCell(e)}
	@doc.bind('Control-Key-U')		{|e| undoCell(e)}
	@doc.bind('Control-Key-u')		{|e| undoCell(e)}

	@doc.bind('Key')				{|e| anyKeyPress(e)}
···

On Thursday 20 June 2002 09:16 pm, Joel VanderWerf wrote:

Anyone know how to bind arrow keys in Tk? The first bind call below does
what I want. The second doesn’t have any apparent effect. My window has
some buttons as well as a canvas, and the buttons have focus, but I
don’t bind arrows in the buttons (tried it, had no effect either).

works

$root.bind “period” do
$canvas.xview “scroll”, 1, “units”
end

#doesn’t work
$root.bind “rightarrow” do
$canvas.xview “scroll”, 1, “units”
end

Albert Wagner wrote:

            @doc.bind('Key-Up')                     {|e| keyUpArrow(e)}
            @doc.bind('Key-Down')                   {|e| keyDownArrow(e)}

Thanks! Following your example, ‘Key-Right’ worked.