@@ -737,169 +737,6 @@ pub struct Modifiers {
737737 pub rctrl2 : bool ,
738738}
739739
740- impl Modifiers {
741- /// Handle letter keys with standard ASCII 'A'..'Z' keycaps.
742- ///
743- /// ONLY pass 'A'..='Z' - nothing else.
744- ///
745- /// You will get a `DecodedKey::Unicode` value with the appropriate lower
746- /// or upper case letter, according to state of the the Caps Lock and
747- /// Shift modifiers.
748- pub ( crate ) fn handle_ascii_2 ( & self , letter : char , handle_ctrl : HandleControl ) -> DecodedKey {
749- debug_assert ! ( letter. is_ascii_uppercase( ) ) ;
750- if handle_ctrl == HandleControl :: MapLettersToUnicode && self . is_ctrl ( ) {
751- // Get a Control code, like Ctrl+C => U+0003
752- const ASCII_UPPERCASE_START_OFFSET : u8 = 64 ;
753- DecodedKey :: Unicode ( ( letter as u8 - ASCII_UPPERCASE_START_OFFSET ) as char )
754- } else if self . is_caps ( ) {
755- // Capital letter
756- DecodedKey :: Unicode ( letter)
757- } else {
758- // Lowercase letter
759- const ASCII_UPPER_TO_LOWER_OFFSET : u8 = 32 ;
760- DecodedKey :: Unicode ( ( letter as u8 + ASCII_UPPER_TO_LOWER_OFFSET ) as char )
761- }
762- }
763-
764- /// Handle letter keys with just two variants (lower and upper case).
765- ///
766- /// Designed for non-ASCII keys, this does not produce control codes.
767- ///
768- /// You will get a `DecodedKey::Unicode` value with the appropriate lower
769- /// or upper case letter, according to state of the the Caps Lock and
770- /// Shift modifiers.
771- ///
772- /// We make you pass both upper and lower case variants to avoid having to
773- /// use the `char::to_lowercase` function.
774- pub ( crate ) fn handle_letter2 ( & self , letter_lower : char , letter_upper : char ) -> DecodedKey {
775- if self . is_caps ( ) {
776- DecodedKey :: Unicode ( letter_upper)
777- } else {
778- DecodedKey :: Unicode ( letter_lower)
779- }
780- }
781-
782- /// Handle letter keys with standard ASCII 'A'..'Z' keycaps with two extra symbols.
783- ///
784- /// ONLY pass 'A'..='Z' - nothing else
785- ///
786- /// You will get a `DecodedKey::Unicode` value with the appropriate lower
787- /// or upper case letter, according to state of the the Caps Lock and
788- /// Shift modifiers. Or, if AltGr is held, you get either the alternate
789- /// character. Useful if your alternate character is e.g. `€`.
790- ///
791- /// We make you pass both upper and lower case variants to avoid having to
792- /// use the `char::to_lowercase` function.
793- pub ( crate ) fn handle_ascii_3 (
794- & self ,
795- letter_upper : char ,
796- alt : char ,
797- handle_ctrl : HandleControl ,
798- ) -> DecodedKey {
799- debug_assert ! ( letter_upper. is_ascii_uppercase( ) ) ;
800- if handle_ctrl == HandleControl :: MapLettersToUnicode && self . is_ctrl ( ) {
801- // Get a Control code, like Ctrl+C => U+0003
802- const ASCII_UPPERCASE_START_OFFSET : u8 = 64 ;
803- DecodedKey :: Unicode ( ( letter_upper as u8 - ASCII_UPPERCASE_START_OFFSET ) as char )
804- } else if self . ralt {
805- // Alternate character
806- DecodedKey :: Unicode ( alt)
807- } else if self . is_caps ( ) {
808- // Capital letter
809- DecodedKey :: Unicode ( letter_upper)
810- } else {
811- // Lowercase letter
812- const ASCII_UPPER_TO_LOWER_OFFSET : u8 = 32 ;
813- DecodedKey :: Unicode ( ( letter_upper as u8 + ASCII_UPPER_TO_LOWER_OFFSET ) as char )
814- }
815- }
816-
817- /// Handle letter keys with standard ASCII 'A'..'Z' keycaps with two extra symbols.
818- ///
819- /// ONLY pass 'A'..='Z' - nothing else
820- ///
821- /// You will get a `DecodedKey::Unicode` value with the appropriate lower
822- /// or upper case letter, according to state of the the Caps Lock and
823- /// Shift modifiers. Or, if AltGr is held, you get either the upper or
824- /// lower case alternate character. Useful if your alternate character is
825- /// e.g. `é` (or `É` if Shift or Caps Lock is enabled).
826- ///
827- /// We make you pass both upper and lower case variants to avoid having to
828- /// use the `char::to_lowercase` function.
829- pub ( crate ) fn handle_ascii_4 (
830- & self ,
831- letter_upper : char ,
832- alt_letter_lower : char ,
833- alt_letter_upper : char ,
834- handle_ctrl : HandleControl ,
835- ) -> DecodedKey {
836- debug_assert ! ( letter_upper. is_ascii_uppercase( ) ) ;
837- if handle_ctrl == HandleControl :: MapLettersToUnicode && self . is_ctrl ( ) {
838- // Get a Control code, like Ctrl+C => U+0003
839- const ASCII_UPPERCASE_START_OFFSET : u8 = 64 ;
840- DecodedKey :: Unicode ( ( letter_upper as u8 - ASCII_UPPERCASE_START_OFFSET ) as char )
841- } else if self . ralt && self . is_caps ( ) {
842- // Capital letter
843- DecodedKey :: Unicode ( alt_letter_upper)
844- } else if self . ralt {
845- // Lowercase letter
846- DecodedKey :: Unicode ( alt_letter_lower)
847- } else if self . is_caps ( ) {
848- // Capital letter
849- DecodedKey :: Unicode ( letter_upper)
850- } else {
851- // Lowercase letter
852- const ASCII_UPPER_TO_LOWER_OFFSET : u8 = 32 ;
853- DecodedKey :: Unicode ( ( letter_upper as u8 + ASCII_UPPER_TO_LOWER_OFFSET ) as char )
854- }
855- }
856-
857- /// Handle numpad keys which are either a character or a raw key
858- pub ( crate ) fn handle_num_pad ( & self , letter : char , key : KeyCode ) -> DecodedKey {
859- if self . numlock {
860- DecodedKey :: Unicode ( letter)
861- } else {
862- DecodedKey :: RawKey ( key)
863- }
864- }
865-
866- /// Handle numpad keys which produce a pair of characters
867- ///
868- /// This is usually just for Numpad Delete.
869- pub ( crate ) fn handle_num_del ( & self , letter : char , other : char ) -> DecodedKey {
870- if self . numlock {
871- DecodedKey :: Unicode ( letter)
872- } else {
873- DecodedKey :: Unicode ( other)
874- }
875- }
876-
877- /// Handle standard two-glyph shifted keys
878- ///
879- /// Caps Lock is ignored here - only shift matters.
880- pub ( crate ) fn handle_symbol2 ( & self , plain : char , shifted : char ) -> DecodedKey {
881- if self . is_shifted ( ) {
882- DecodedKey :: Unicode ( shifted)
883- } else {
884- DecodedKey :: Unicode ( plain)
885- }
886- }
887-
888- /// Handle standard three-glyph shifted keys
889- ///
890- /// Caps Lock is ignored here - only shift matters. AltGr gets you the
891- /// alternate letter, regardless of Shift status.
892- pub ( crate ) fn handle_symbol3 ( & self , plain : char , shifted : char , alt : char ) -> DecodedKey {
893- if self . is_altgr ( ) {
894- DecodedKey :: Unicode ( alt)
895- } else if self . is_shifted ( ) {
896- DecodedKey :: Unicode ( shifted)
897- } else {
898- DecodedKey :: Unicode ( plain)
899- }
900- }
901- }
902-
903740/// Contains either a Unicode character, or a raw key code.
904741#[ derive( Debug , PartialEq , Eq , Copy , Clone ) ]
905742pub enum DecodedKey {
@@ -1325,6 +1162,167 @@ impl Modifiers {
13251162 pub const fn is_caps ( & self ) -> bool {
13261163 self . is_shifted ( ) ^ self . capslock
13271164 }
1165+
1166+ /// Handle letter keys with standard ASCII 'A'..'Z' keycaps.
1167+ ///
1168+ /// ONLY pass 'A'..='Z' - nothing else.
1169+ ///
1170+ /// You will get a `DecodedKey::Unicode` value with the appropriate lower
1171+ /// or upper case letter, according to state of the the Caps Lock and
1172+ /// Shift modifiers.
1173+ pub ( crate ) fn handle_ascii_2 ( & self , letter : char , handle_ctrl : HandleControl ) -> DecodedKey {
1174+ debug_assert ! ( letter. is_ascii_uppercase( ) ) ;
1175+ if handle_ctrl == HandleControl :: MapLettersToUnicode && self . is_ctrl ( ) {
1176+ // Get a Control code, like Ctrl+C => U+0003
1177+ const ASCII_UPPERCASE_START_OFFSET : u8 = 64 ;
1178+ DecodedKey :: Unicode ( ( letter as u8 - ASCII_UPPERCASE_START_OFFSET ) as char )
1179+ } else if self . is_caps ( ) {
1180+ // Capital letter
1181+ DecodedKey :: Unicode ( letter)
1182+ } else {
1183+ // Lowercase letter
1184+ const ASCII_UPPER_TO_LOWER_OFFSET : u8 = 32 ;
1185+ DecodedKey :: Unicode ( ( letter as u8 + ASCII_UPPER_TO_LOWER_OFFSET ) as char )
1186+ }
1187+ }
1188+
1189+ /// Handle letter keys with just two variants (lower and upper case).
1190+ ///
1191+ /// Designed for non-ASCII keys, this does not produce control codes.
1192+ ///
1193+ /// You will get a `DecodedKey::Unicode` value with the appropriate lower
1194+ /// or upper case letter, according to state of the the Caps Lock and
1195+ /// Shift modifiers.
1196+ ///
1197+ /// We make you pass both upper and lower case variants to avoid having to
1198+ /// use the `char::to_lowercase` function.
1199+ pub ( crate ) fn handle_letter2 ( & self , letter_lower : char , letter_upper : char ) -> DecodedKey {
1200+ if self . is_caps ( ) {
1201+ DecodedKey :: Unicode ( letter_upper)
1202+ } else {
1203+ DecodedKey :: Unicode ( letter_lower)
1204+ }
1205+ }
1206+
1207+ /// Handle letter keys with standard ASCII 'A'..'Z' keycaps with two extra symbols.
1208+ ///
1209+ /// ONLY pass 'A'..='Z' - nothing else
1210+ ///
1211+ /// You will get a `DecodedKey::Unicode` value with the appropriate lower
1212+ /// or upper case letter, according to state of the the Caps Lock and
1213+ /// Shift modifiers. Or, if AltGr is held, you get either the alternate
1214+ /// character. Useful if your alternate character is e.g. `€`.
1215+ ///
1216+ /// We make you pass both upper and lower case variants to avoid having to
1217+ /// use the `char::to_lowercase` function.
1218+ pub ( crate ) fn handle_ascii_3 (
1219+ & self ,
1220+ letter_upper : char ,
1221+ alt : char ,
1222+ handle_ctrl : HandleControl ,
1223+ ) -> DecodedKey {
1224+ debug_assert ! ( letter_upper. is_ascii_uppercase( ) ) ;
1225+ if handle_ctrl == HandleControl :: MapLettersToUnicode && self . is_ctrl ( ) {
1226+ // Get a Control code, like Ctrl+C => U+0003
1227+ const ASCII_UPPERCASE_START_OFFSET : u8 = 64 ;
1228+ DecodedKey :: Unicode ( ( letter_upper as u8 - ASCII_UPPERCASE_START_OFFSET ) as char )
1229+ } else if self . ralt {
1230+ // Alternate character
1231+ DecodedKey :: Unicode ( alt)
1232+ } else if self . is_caps ( ) {
1233+ // Capital letter
1234+ DecodedKey :: Unicode ( letter_upper)
1235+ } else {
1236+ // Lowercase letter
1237+ const ASCII_UPPER_TO_LOWER_OFFSET : u8 = 32 ;
1238+ DecodedKey :: Unicode ( ( letter_upper as u8 + ASCII_UPPER_TO_LOWER_OFFSET ) as char )
1239+ }
1240+ }
1241+
1242+ /// Handle letter keys with standard ASCII 'A'..'Z' keycaps with two extra symbols.
1243+ ///
1244+ /// ONLY pass 'A'..='Z' - nothing else
1245+ ///
1246+ /// You will get a `DecodedKey::Unicode` value with the appropriate lower
1247+ /// or upper case letter, according to state of the the Caps Lock and
1248+ /// Shift modifiers. Or, if AltGr is held, you get either the upper or
1249+ /// lower case alternate character. Useful if your alternate character is
1250+ /// e.g. `é` (or `É` if Shift or Caps Lock is enabled).
1251+ ///
1252+ /// We make you pass both upper and lower case variants to avoid having to
1253+ /// use the `char::to_lowercase` function.
1254+ pub ( crate ) fn handle_ascii_4 (
1255+ & self ,
1256+ letter_upper : char ,
1257+ alt_letter_lower : char ,
1258+ alt_letter_upper : char ,
1259+ handle_ctrl : HandleControl ,
1260+ ) -> DecodedKey {
1261+ debug_assert ! ( letter_upper. is_ascii_uppercase( ) ) ;
1262+ if handle_ctrl == HandleControl :: MapLettersToUnicode && self . is_ctrl ( ) {
1263+ // Get a Control code, like Ctrl+C => U+0003
1264+ const ASCII_UPPERCASE_START_OFFSET : u8 = 64 ;
1265+ DecodedKey :: Unicode ( ( letter_upper as u8 - ASCII_UPPERCASE_START_OFFSET ) as char )
1266+ } else if self . ralt && self . is_caps ( ) {
1267+ // Capital letter
1268+ DecodedKey :: Unicode ( alt_letter_upper)
1269+ } else if self . ralt {
1270+ // Lowercase letter
1271+ DecodedKey :: Unicode ( alt_letter_lower)
1272+ } else if self . is_caps ( ) {
1273+ // Capital letter
1274+ DecodedKey :: Unicode ( letter_upper)
1275+ } else {
1276+ // Lowercase letter
1277+ const ASCII_UPPER_TO_LOWER_OFFSET : u8 = 32 ;
1278+ DecodedKey :: Unicode ( ( letter_upper as u8 + ASCII_UPPER_TO_LOWER_OFFSET ) as char )
1279+ }
1280+ }
1281+
1282+ /// Handle numpad keys which are either a character or a raw key
1283+ pub ( crate ) fn handle_num_pad ( & self , letter : char , key : KeyCode ) -> DecodedKey {
1284+ if self . numlock {
1285+ DecodedKey :: Unicode ( letter)
1286+ } else {
1287+ DecodedKey :: RawKey ( key)
1288+ }
1289+ }
1290+
1291+ /// Handle numpad keys which produce a pair of characters
1292+ ///
1293+ /// This is usually just for Numpad Delete.
1294+ pub ( crate ) fn handle_num_del ( & self , letter : char , other : char ) -> DecodedKey {
1295+ if self . numlock {
1296+ DecodedKey :: Unicode ( letter)
1297+ } else {
1298+ DecodedKey :: Unicode ( other)
1299+ }
1300+ }
1301+
1302+ /// Handle standard two-glyph shifted keys
1303+ ///
1304+ /// Caps Lock is ignored here - only shift matters.
1305+ pub ( crate ) fn handle_symbol2 ( & self , plain : char , shifted : char ) -> DecodedKey {
1306+ if self . is_shifted ( ) {
1307+ DecodedKey :: Unicode ( shifted)
1308+ } else {
1309+ DecodedKey :: Unicode ( plain)
1310+ }
1311+ }
1312+
1313+ /// Handle standard three-glyph shifted keys
1314+ ///
1315+ /// Caps Lock is ignored here - only shift matters. AltGr gets you the
1316+ /// alternate letter, regardless of Shift status.
1317+ pub ( crate ) fn handle_symbol3 ( & self , plain : char , shifted : char , alt : char ) -> DecodedKey {
1318+ if self . is_altgr ( ) {
1319+ DecodedKey :: Unicode ( alt)
1320+ } else if self . is_shifted ( ) {
1321+ DecodedKey :: Unicode ( shifted)
1322+ } else {
1323+ DecodedKey :: Unicode ( plain)
1324+ }
1325+ }
13281326}
13291327
13301328// ****************************************************************************
0 commit comments