MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: fails?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88921] Re: fails?
  • From: "Chris Osborn" <chrisosb at gmail.com>
  • Date: Wed, 21 May 2008 14:51:10 -0400 (EDT)
  • References: <200805190915.FAA12563@smc.vnet.net>

Thanks Jason,

Too bad we have no solution.
I have cooked up something that's a little ugly, but it works.  It's
called "KeyHandler" and I think it recognizes most of the keys on the
keyboard.

If you want to mix key event handling with other types of event
handling you will need to nest the event handlers.

KeyHandler[code_, action_]
executions "code", calling "action" when a key is pressed, and passing
"action" the string representing the character.

e.g. KeyHandler["some string", Print] prints out the keys that are pressed.

Chris


ClearAll[charRange, actionTable, KeyHandler];
charRange[c1_, c2_] :=
  FromCharacterCode /@
   Table[i, {i, ToCharacterCode[c1] // First,
     ToCharacterCode[c2] // First}];

actionTable[lst_List, action_] :=
  Function[key, {"KeyDown", key} :> action[key]] /@ lst;

SetAttributes[KeyHandler, HoldFirst];
KeyHandler[code_, action_] := EventHandler[code,
   actionTable[
    charRange["a", "z"]~Join~charRange["A", "Z"]~Join~
     charRange["0", "9"]~
     Join~{"~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-",
       "_", "=", "+", "[", "]", "\\", "|", ";", ":", "'", "\"", ",",
      "<", ".", ">", "/", "?", " ", "\t", "\r", FromCharacterCode[27],
       FromCharacterCode[8]}, action]];





On Mon, May 19, 2008 at 6:44 AM, J. McKenzie Alexander <jalex at lse.ac.uk> wrote:
> I found this problem as well when I tried to write an EventHandler for
> generating a custom input field.  I described the problem you report in a
> question filed with Wolfram Technical Support (identification number TS
> 13327) on 9 May.  I never received a reply beyond the automated
> acknowledgement.
>
> So, yes, I think there is good reason to believe that
> CurrentValue["EventKey"] is broken.
>
> Jason
>
> On 19 May 2008, at 10:15, Chris Osborn wrote:
>
>> To all,
>>
>> I am unable to create an expression that reports what key has been
>> pressed.  It seems that CurrentValue["EventKey"] always returns
>> "None".
>>
>>
>> Here is the code:
>>
>> EventHandler["a string", "KeyDown" :> Print[CurrentValue["EventKey"]]]
>>
>>
>> I get similar results with:
>>
>> EventHandler[Dynamic[key],
>> "KeyDown" :> (key = CurrentValue["EventKey"])]
>>
>>
>> Thanks in advance,
>> Chris
>>
>
> --
> Dr J. McKenzie Alexander
> Department of Philosophy, Logic and Scientific Method
> London School of Economics and Political Science
> Houghton Street, London WC2A 2AE
>
>
>
>
> Please access the attached hyperlink for an important electronic
> communications disclaimer:
> http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
>


  • Prev by Date: Re: Cannot NSolve a system of equations
  • Next by Date: Re: DumpSave of packages
  • Previous by thread: CurrentValue["EventKey"] fails?
  • Next by thread: Possible Bug Report: CoefficientList