@@ -37,7 +37,6 @@ import flash.media.*;
37
37
import flash.net.* ;
38
38
import flash.system.System ;
39
39
import flash.text.TextField ;
40
- import flash.ui.Keyboard ;
41
40
import flash.utils.* ;
42
41
43
42
import interpreter.* ;
@@ -949,37 +948,31 @@ public class ScratchRuntime {
949
948
950
949
public function keyDown (evt :KeyboardEvent ):void {
951
950
shiftIsDown = evt. shiftKey ;
952
- var ch: int = getCharCode(evt);
951
+ var ch: int = evt. charCode ;
952
+ if (evt. charCode == 0 ) ch = mapArrowKey(evt. keyCode );
953
+ if ((65 <= ch) && (ch <= 90 )) ch += 32 ; // map A-Z to a-z
953
954
if (! (evt. target is TextField )) startKeyHats(ch);
954
955
if (ch < 128 ) keyIsDown[ ch] = true ;
955
956
}
956
957
957
958
public function keyUp (evt :KeyboardEvent ):void {
958
959
shiftIsDown = evt. shiftKey ;
959
- var ch: int = getCharCode(evt);
960
+ var ch: int = evt. charCode ;
961
+ if (evt. charCode == 0 ) ch = mapArrowKey(evt. keyCode );
962
+ if ((65 <= ch) && (ch <= 90 )) ch += 32 ; // map A-Z to a-z
960
963
if (ch < 128 ) keyIsDown[ ch] = false ;
961
964
}
962
965
963
966
private function clearKeyDownArray ():void {
964
967
for (var i: int = 0 ; i < 128 ; i++ ) keyIsDown[ i] = false ;
965
968
}
966
969
967
- // Get an ASCII value for the key pressed:
968
- // - Latin letters will be normalized to lower-case
969
- // - Arrows will be mapped to ASCII/Unicode delimiters (this is a traditional hack in Scratch 2.0; see mapArrowKey)
970
- private static function getCharCode (evt :KeyboardEvent ):int {
971
- var arrowCode: int = mapArrowKey(evt. keyCode );
972
- if (arrowCode) return arrowCode;
973
- return String . fromCharCode (evt. keyCode ). toLowerCase (). charCodeAt (0 );
974
- }
975
-
976
- // Map key codes for arrow keys to ASCII delimiters, and other key codes to zero.
977
- // See https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
978
- private static function mapArrowKey (keyCode :int ):int {
979
- if (keyCode == Keyboard . LEFT ) return 28 ; // file separator
980
- if (keyCode == Keyboard . UP ) return 30 ; // group separator
981
- if (keyCode == Keyboard . RIGHT ) return 29 ; // record separator
982
- if (keyCode == Keyboard . DOWN ) return 31 ; // unit separator
970
+ private function mapArrowKey (keyCode :int ):int {
971
+ // map key codes for arrow keys to ASCII, other key codes to zero
972
+ if (keyCode == 37 ) return 28 ;
973
+ if (keyCode == 38 ) return 30 ;
974
+ if (keyCode == 39 ) return 29 ;
975
+ if (keyCode == 40 ) return 31 ;
983
976
return 0 ;
984
977
}
985
978
0 commit comments