diff --git a/src/SimConnect.NET/Enums/SimConnectInputEventType.cs b/src/SimConnect.NET/Enums/SimConnectInputEventType.cs
index 718a3ab..233196f 100644
--- a/src/SimConnect.NET/Enums/SimConnectInputEventType.cs
+++ b/src/SimConnect.NET/Enums/SimConnectInputEventType.cs
@@ -10,11 +10,6 @@ namespace SimConnect.NET
///
public enum SimConnectInputEventType
{
- ///
- /// No data type specification required (C++ only).
- ///
- None,
-
///
/// Specifies a double value.
///
diff --git a/src/SimConnect.NET/InputEvents/InputEventManager.cs b/src/SimConnect.NET/InputEvents/InputEventManager.cs
index 11a939d..2fd6025 100644
--- a/src/SimConnect.NET/InputEvents/InputEventManager.cs
+++ b/src/SimConnect.NET/InputEvents/InputEventManager.cs
@@ -8,6 +8,7 @@
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
+using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SimConnect.NET.Events;
@@ -179,7 +180,9 @@ await Task.Run(
using (cancellationToken.Register(() => tcs.TrySetCanceled()))
{
- return await tcs.Task.ConfigureAwait(false);
+ var value = await tcs.Task.ConfigureAwait(false);
+ value.Hash = hash; // Set the hash for reference
+ return value;
}
}
finally
@@ -591,14 +594,13 @@ private void ProcessEnumerateInputEvents(IntPtr ppData)
var typeValue = Marshal.ReadInt32(currentPtr);
var inputEventType = Enum.IsDefined(typeof(SimConnectInputEventType), typeValue)
? (SimConnectInputEventType)typeValue
- : SimConnectInputEventType.None; // Default to None if invalid
+ : SimConnectInputEventType.DoubleValue; // Default to None if invalid
// Convert to SimConnectDataType for the descriptor
var type = inputEventType switch
{
SimConnectInputEventType.DoubleValue => SimConnectDataType.FloatDouble,
SimConnectInputEventType.StringValue => SimConnectDataType.String128,
- SimConnectInputEventType.None => SimConnectDataType.FloatDouble, // Default to double for unspecified type
_ => SimConnectDataType.FloatDouble, // Default fallback
};
@@ -671,26 +673,37 @@ private void ProcessGetInputEvent(IntPtr ppData)
{
try
{
- var recvGet = Marshal.PtrToStructure(ppData);
+ var recvGet = Marshal.PtrToStructure(ppData);
+ int headerSize = Marshal.SizeOf();
+ int totalSize = checked((int)recvGet.Size);
+ int payloadSize = totalSize - headerSize;
+ System.Diagnostics.Debug.WriteLine($"[InputEventManager] Payload size: {payloadSize}");
+ IntPtr pValue = IntPtr.Add(ppData, headerSize);
// Extract value based on the type
object value;
switch (recvGet.Type)
{
case SimConnectInputEventType.DoubleValue:
- value = Marshal.PtrToStructure(recvGet.Value);
+ value = Marshal.PtrToStructure(pValue);
break;
case SimConnectInputEventType.StringValue:
- value = Marshal.PtrToStringAnsi(recvGet.Value) ?? string.Empty;
+ byte[] buf = new byte[payloadSize];
+ Marshal.Copy(pValue, buf, 0, buf.Length);
+ int nul = Array.IndexOf(buf, (byte)0);
+ int len = nul >= 0 ? nul : buf.Length;
+ value = Encoding.ASCII.GetString(buf, 0, len);
break;
default:
- value = recvGet.Value.ToInt64();
+ byte[] defBuf = new byte[payloadSize];
+ Marshal.Copy(pValue, defBuf, 0, defBuf.Length);
+ value = defBuf;
+ value = BitConverter.ToDouble(defBuf, 0);
break;
}
var inputEventValue = new InputEventValue
{
- Hash = recvGet.RequestId,
Type = recvGet.Type,
Value = value,
};
diff --git a/src/SimConnect.NET/Structs/SimConnectRecvGetInputEvent.cs b/src/SimConnect.NET/Structs/SimConnectRecvGetInputEventHeader.cs
similarity index 68%
rename from src/SimConnect.NET/Structs/SimConnectRecvGetInputEvent.cs
rename to src/SimConnect.NET/Structs/SimConnectRecvGetInputEventHeader.cs
index 13bcba9..1166c55 100644
--- a/src/SimConnect.NET/Structs/SimConnectRecvGetInputEvent.cs
+++ b/src/SimConnect.NET/Structs/SimConnectRecvGetInputEventHeader.cs
@@ -1,13 +1,13 @@
-//
+//
// Copyright (c) BARS. All rights reserved.
//
namespace SimConnect.NET
{
///
- /// The SimConnectRecvGetInputEvent structure is used to return the value of a specific input event.
+ /// The SimConnectRecvGetInputEventHeader structure is used to return the header of a specific input event including the type but without the value.
///
- public struct SimConnectRecvGetInputEvent
+ public struct SimConnectRecvGetInputEventHeader
{
///
/// Gets or sets the total size of the returned structure in bytes.
@@ -33,10 +33,5 @@ public struct SimConnectRecvGetInputEvent
/// Gets or sets the type of the input event. This is used to cast the Value to the correct type.
///
public SimConnectInputEventType Type { get; set; }
-
- ///
- /// Gets or sets the value of the requested input event, which should be cast to the correct format (float / string).
- ///
- public IntPtr Value { get; set; }
}
}