KeyDown Event returns incorrect ascii values when used with a spanish
layout keyboard.

I followed the calculator tutorial
<http://www.macromedia.com/devnet/flex/articles/calculator.html>
and tried to extend it to accept keyboard input.
I noticed that the ascii values are returned, according to the
documentation, based on an us english layout keyboard.

It works as documented, but not as I expected.  I think that function is
completely useless for people with a non-us keyboard,
and keyboard layout cannot be assumed, as we are developing applications
for the internet.

Well, when I tried to get the ascii codes, I was not able to get the
correct codes.
For example, when i press Shift + 2, I get an at "@" sign , instead of a
quote sign, as if I had an english keyboard.
I mean, that is very cool when writing games when I need to get full
control of the shift, control, etc, but when I was trying to
get regular keyboard input for a simple calculator, i was not able to
enter the equal sign by pressing
Shift + 0, as I would do in any application using my normal spanish
keyboard, to enter the "=", but I get the ")" instead.

Can anyone tell me what am i doing wrong, or tell me the rationale
behind this design?

I'm attaching my modified calculator in case someone wants to review it.1

Thanks in advance,

    Daniel Montero
    [EMAIL PROTECTED]





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"; xmlns="*">

<CalculatorHandlers id="calcHandlers" calcView="{this}"/>

<mx:Panel title="Calculator" keyUp="calckey(String.fromCharCode(event.ascii))">
        <mx:Label id="calcDisplay" width="150" textAlign="right"/>
        
    <mx:Grid>
      <mx:GridRow>
        <mx:GridItem colSpan="2"><mx:Button label="Clear" width="70" 
click="calcHandlers.clearAll()" /></mx:GridItem>
        <mx:GridItem><mx:Button label="CE" width="30" 
click="calcHandlers.clearEntry()" /></mx:GridItem>
        <mx:GridItem><mx:Button label="+" width="30" 
click="calcHandlers.setOperation('add')" /></mx:GridItem>
      </mx:GridRow>
      <mx:GridRow>
        <mx:GridItem><mx:Button label="1" width="30" 
click="calcHandlers.addNumber('1')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="2" width="30" 
click="calcHandlers.addNumber('2')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="3" width="30" 
click="calcHandlers.addNumber('3')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="-" width="30" 
click="calcHandlers.setOperation('subtract')" /></mx:GridItem>
      </mx:GridRow>
      <mx:GridRow>
        <mx:GridItem><mx:Button label="4" width="30" 
click="calcHandlers.addNumber('4')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="5" width="30" 
click="calcHandlers.addNumber('5')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="6" width="30" 
click="calcHandlers.addNumber('6')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="*" width="30" 
click="calcHandlers.setOperation('multiply')" /></mx:GridItem>
      </mx:GridRow>
      <mx:GridRow>
        <mx:GridItem><mx:Button label="7" width="30" 
click="calcHandlers.addNumber('7')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="8" width="30" 
click="calcHandlers.addNumber('8')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="9" width="30" 
click="calcHandlers.addNumber('9')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="/" width="30" 
click="calcHandlers.setOperation('divide')" /></mx:GridItem>
      </mx:GridRow>
      <mx:GridRow>
        <mx:GridItem><mx:Button label="0" width="30" 
click="calcHandlers.addNumber('0')" /></mx:GridItem>
        <mx:GridItem><mx:Button label="." width="30" 
click="calcHandlers.addNumber('.')" /></mx:GridItem>
        <mx:GridItem colSpan="2">
          <mx:Button label="=" width="70" click="calcHandlers.doOperation()" 
/></mx:GridItem>
      </mx:GridRow>
    </mx:Grid>  
</mx:Panel>
<mx:Script>
<![CDATA[
        function calckey(key:String):Void{
                switch (key){
                case '+':case '-':
                case '*':case '/':
                        calcHandlers.setOperation(key);
                        break;
                case '0':case '1':case '2':
                case '3':case '4':case '5':
                case '6':case '7':case '8':
                case '9':case '.':
                        calcHandlers.addNumber(key);
                        break;
                case '=':
                        calcHandlers.doOperation();
                        break;
                default://
                        alert('nothing:'+key);
                        break;
                }
        }
]]>
</mx:Script>
</mx:Application>

Reply via email to