jinsu_kim
jinsu_kim

Reputation: 7

Bind number key (numeric keypad)

I'm trying to make a fancy calculator (using button widget).

It necessary input numberkey (like 1,2,3 or num1,num2).

So i tried like this

bind . <key 1> {multiply $numberKey}

or

bind . <1> {multiply $numberKey}

But it's not working.

how can i bind the numeric key?

Upvotes: 0

Views: 662

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137607

The name of the 1 key is 1, without <…> around it.

bind . 1 {puts "pressed one"}

You can also use the full name, which needs to be described as a KeyPress event (which you can shorten to Key if you want):

bind . <KeyPress-1> {puts "pressed one"}

To get the name of an arbitrary key, try this little script:

bind . <KeyPress> {puts "pressed %K (producing character %A)"}

That prints the name of the key (what you need with a KeyPress prefix as a description) when you press the key. Single character keysyms can be used directly, but numbers cannot be just put in <…> because that's special cased to mean mouse button presses instead (as those are more commonly bound to specifically in most applications).

Upvotes: 1

Related Questions