void EncodeKeymap(Keymap map, BinaryWriter w) { int max = 0; foreach (KeyValuePair <int, int> kvp in map.Entries) { if (kvp.Key > max) { max = kvp.Key; } } w.Write(max); for (int scancode = 0; scancode < max; ++scancode) { if (map.Entries.ContainsKey(scancode)) { w.Write((char)map.Entries [scancode]); } else { w.Write((char)0); } } }
public void Decode(out int keymask, out int statebit, out Keymap defaultMap, out Keymap shiftedMap, Stream input) { using (BinaryReader br = new BinaryReader(input)) { keymask = br.ReadChar(); statebit = br.ReadChar(); defaultMap = DecodeKeymap(br); shiftedMap = DecodeKeymap(br); } }
public void Encode(int keymask, int statebit, Keymap defaultMap, Keymap shiftedMap, Stream output) { using (BinaryWriter bw = new BinaryWriter(output)) { bw.Write((char)keymask); bw.Write((char)statebit); EncodeKeymap(defaultMap, bw); EncodeKeymap(shiftedMap, bw); } }
Keymap DecodeKeymap(BinaryReader r) { Keymap map = new Keymap(); int count = r.ReadInt32(); for (int scancode = 0; scancode < count; ++scancode) { map.Entries [scancode] = r.ReadChar(); } return(map); }
public bool ParseStatement(Tokenizer t) { bool err = false; Token token = t.Read(); if (token == null) { return(false); } if (token.Type == TokenType.Alphanumeric) { switch (token.Text) { case "keymask": keymask = ReadEqInt(t); break; case "statebit": statebit = ReadEqInt(t); break; case "default": Console.WriteLine("Parsing `default' keymap..."); defaultMap = ReadMap(t); break; case "shifted": Console.WriteLine("Parsing `shifted' keymap..."); shiftedMap = ReadMap(t); break; default: err = true; break; } } else { err = true; } if (err) { throw new UnexpectedTokenException(token, "<unknown>"); } return(true); }
Keymap DecodeKeymap(BinaryReader r) { Keymap map = new Keymap(); int count = r.ReadInt32(); int specConv = (int)SpecialKeys.Control - 129; for (int scancode = 0; scancode < count; ++scancode) { byte value = r.ReadByte(); if (value > 128) { map.Entries [scancode] = (int)value + specConv; } else { map.Entries [scancode] = value; } } return(map); }
void EncodeKeymap(Keymap map, BinaryWriter w) { int max = 0; foreach (KeyValuePair <int, int> kvp in map.Entries) { if (kvp.Key > max) { max = kvp.Key; } } w.Write(max); for (int scancode = 0; scancode < max; ++scancode) { int value = map.Entries [scancode]; int specConv = 129 - (int)SpecialKeys.Control; if (!map.Entries.ContainsKey(scancode)) { w.Write((byte)0); continue; ; } if (value > 0xFFFF) { value = value + specConv; } if (value > 255) { Console.Error.WriteLine("Warning: key `{0}' is too large", value); } w.Write((byte)value); } }
public Keymap ReadMap(Tokenizer t) { Keymap map = new Keymap(); Token tok; ReadSectionOpen(t); do { int scancode, key; tok = t.Read(); if (tok == null) { throw new UnexpectedEndOfFileException(t, "}"); } if (tok.Text == "}") { break; } else { t.PutBack(tok); } scancode = ReadInt(t); key = ReadEqChar(t); ReadEnd(t); map.Entries [scancode] = key; } while (true); return(map); }
public Keymap ReadMap (Tokenizer t) { Keymap map = new Keymap (); Token tok; ReadSectionOpen (t); do { int scancode, key; tok = t.Read (); if (tok == null) throw new UnexpectedEndOfFileException (t, "}"); if (tok.Text == "}") break; else t.PutBack (tok); scancode = ReadInt (t); key = ReadEqChar (t); ReadEnd (t); map.Entries [scancode] = key; } while (true); return map; }
public bool ParseStatement (Tokenizer t) { bool err = false; Token token = t.Read (); if (token == null) return false; if (token.Type == TokenType.Alphanumeric) { switch (token.Text) { case "keymask": keymask = ReadEqInt (t); break; case "statebit": statebit = ReadEqInt (t); break; case "default": Console.WriteLine ("Parsing `default' keymap..."); defaultMap = ReadMap (t); break; case "shifted": Console.WriteLine ("Parsing `shifted' keymap..."); shiftedMap = ReadMap (t); break; default: err = true; break; } } else err = true; if (err) throw new UnexpectedTokenException (token, "<unknown>"); return true; }
public void Decode (out int keymask, out int statebit, out Keymap defaultMap, out Keymap shiftedMap, Stream input) { using (BinaryReader br = new BinaryReader (input)) { keymask = br.ReadChar (); statebit = br.ReadChar (); defaultMap = DecodeKeymap (br); shiftedMap = DecodeKeymap (br); } }
public void Encode (int keymask, int statebit, Keymap defaultMap, Keymap shiftedMap, Stream output) { using (BinaryWriter bw = new BinaryWriter (output)) { bw.Write ((char) keymask); bw.Write ((char) statebit); EncodeKeymap (defaultMap, bw); EncodeKeymap (shiftedMap, bw); } }
Keymap DecodeKeymap (BinaryReader r) { Keymap map = new Keymap (); int count = r.ReadInt32 (); for (int scancode = 0; scancode < count; ++scancode) { map.Entries [scancode] = r.ReadChar (); } return map; }
void EncodeKeymap (Keymap map, BinaryWriter w) { int max = 0; foreach (KeyValuePair<int, int> kvp in map.Entries) { if (kvp.Key > max) max = kvp.Key; } w.Write (max); for (int scancode = 0; scancode < max; ++scancode) { if (map.Entries.ContainsKey (scancode)) w.Write ((char) map.Entries [scancode]); else w.Write ((char) 0); } }
Keymap DecodeKeymap (BinaryReader r) { Keymap map = new Keymap (); int count = r.ReadInt32 (); int specConv = (int) SpecialKeys.Control - 129; for (int scancode = 0; scancode < count; ++scancode) { byte value = r.ReadByte (); if (value > 128) map.Entries [scancode] = (int) value + specConv; else map.Entries [scancode] = value; } return map; }
void EncodeKeymap (Keymap map, BinaryWriter w) { int max = 0; foreach (KeyValuePair<int, int> kvp in map.Entries) { if (kvp.Key > max) max = kvp.Key; } w.Write (max); for (int scancode = 0; scancode < max; ++scancode) { int value = map.Entries [scancode]; int specConv = 129 - (int) SpecialKeys.Control; if (!map.Entries.ContainsKey (scancode)) { w.Write ((byte) 0); continue; ; } if (value > 0xFFFF) value = value + specConv; if (value > 255) Console.Error.WriteLine ("Warning: key `{0}' is too large", value); w.Write ((byte) value); } }