|
| 1 | +//////////////////////////////////////////////////////////////////////////////// |
| 2 | +// The MIT License (MIT) |
| 3 | +// |
| 4 | +// Copyright (c) 2019 Tim Stair |
| 5 | +// |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +// of this software and associated documentation files (the "Software"), to deal |
| 8 | +// in the Software without restriction, including without limitation the rights |
| 9 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +// copies of the Software, and to permit persons to whom the Software is |
| 11 | +// furnished to do so, subject to the following conditions: |
| 12 | +// |
| 13 | +// The above copyright notice and this permission notice shall be included in all |
| 14 | +// copies or substantial portions of the Software. |
| 15 | +// |
| 16 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +// SOFTWARE. |
| 23 | +//////////////////////////////////////////////////////////////////////////////// |
| 24 | + |
| 25 | +using System.IO; |
| 26 | +using KeyCap.Util; |
| 27 | + |
| 28 | +namespace KeyCap.Format |
| 29 | +{ |
| 30 | + public abstract class BaseIOConfig |
| 31 | + { |
| 32 | + public int Flags { get; set; } |
| 33 | + // https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes |
| 34 | + public byte VirtualKey { get; set; } |
| 35 | + public int Parameter { get; set; } |
| 36 | + |
| 37 | + public BaseIOConfig() { } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Constructor for an InputConfig |
| 41 | + /// </summary> |
| 42 | + /// <param name="byFlags">The flags defining the input</param> |
| 43 | + /// <param name="byVirtualKey">The value of the input</param> |
| 44 | + /// <param name="eKeyArgs">The input key arguments from user input</param> |
| 45 | + public BaseIOConfig(int nFlags, byte byVirtualKey, int nParameter) |
| 46 | + { |
| 47 | + Flags = nFlags; |
| 48 | + VirtualKey = byVirtualKey; |
| 49 | + Parameter = nParameter; |
| 50 | + } |
| 51 | + |
| 52 | + public BaseIOConfig(Stream zStream) |
| 53 | + { |
| 54 | + Flags = StreamUtil.ReadIntFromStream(zStream); |
| 55 | + VirtualKey = StreamUtil.ReadByteFromStream(zStream); |
| 56 | + StreamUtil.ReadByteFromStream(zStream); |
| 57 | + StreamUtil.ReadByteFromStream(zStream); |
| 58 | + StreamUtil.ReadByteFromStream(zStream); |
| 59 | + Parameter = StreamUtil.ReadIntFromStream(zStream); |
| 60 | + } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Determines if the input type is flagged (as the there are multiple flags) |
| 64 | + /// </summary> |
| 65 | + /// <param name="eFlag">Flag to check for</param> |
| 66 | + /// <returns>true if the flag bit is 1, false otherwise</returns> |
| 67 | + public bool IsFlaggedAs(System.Enum eFlag) |
| 68 | + { |
| 69 | + return BitUtil.IsFlagged(Flags, eFlag); |
| 70 | + } |
| 71 | + |
| 72 | + public abstract string GetDescription(); |
| 73 | + |
| 74 | + public void SerializeToStream(Stream zStream) |
| 75 | + { |
| 76 | + StreamUtil.WriteIntToStream(zStream, Flags); |
| 77 | + zStream.WriteByte(VirtualKey); |
| 78 | + zStream.WriteByte(0); |
| 79 | + zStream.WriteByte(0); |
| 80 | + zStream.WriteByte(0); |
| 81 | + StreamUtil.WriteIntToStream(zStream, Parameter); |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments