Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Dynamically updated CurrentValue: I want to know which key is being pressed?
Replies: 3   Last Post: Jan 14, 2013 11:28 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Albert Retey

Posts: 688
Registered: 7/15/08
Re: Dynamically updated CurrentValue: I want to know which key is
Posted: Jan 14, 2013 11:28 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi,
>>
>>
>> I think you are looking for "EventKey":
>>
>>
>>
>> EventHandler[Graphics@Rectangle[], {
>>
>> "KeyDown" :> Print[CurrentValue["EventKey"]]
>>
>> }]
>>
>>
>>
>> hth,
>>
>>
>>
>> albert

>
>
> But why not all keys are catched by "EventKey"? For example, pressing
> "a", "i", "o", "p" etc. does nothing. Why?
>


I don't know what exactly is the reason why it doesn't work for you. I
can see three possible causes:

1) There are built in keyboard shortcuts which "eat up" what you type
before the EventHandle will even see them, typical examples are things
like Ctrl-C on Windows. Unfortunately I don't think there is a
documented way to change that.

2) Many of the keys are only giving None for CurrentValue["EventKeys"],
presumably WRI only has implemented the smallest common set available on
all supported OS...

3) The selection state is not what it should be. With that respect my
example using a Graphics is suboptimal as it needs some tricks to
actually select the EventHandler and not the Graphics object. You might
want to use something like EventHandler["hello", {"KeyDown" :>
Print[CurrentValue["EventKey"]]}] instead, where putting the cursor
within the hello does the right thing...

The following makes the Graphics example somewhat easier to use (just
clicking into the graphic will make the selection such that the keyboard
events are catched by the EventHandler):

EventHandler[
Style[Graphics[Rectangle[]],
Selectable -> False], {"KeyDown" :>
MessageDialog[CurrentValue["EventKey"]]}
]


hth,

albert





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.