On 2005-03-16, Mark A Nadig <mn****@wind2.nadaspam.com> wrote:
Hi Tom,
I think you may have already answered this question on another thread
from 1-28-04 http://www.mcse.ms/archive107-2004-1-337551.html
However, I'm having a heck of a time converting the c# code for the
INPUT_RECORD struct and so I can't write the DllImport stmt. Here's
the c# code you wrote a year ago :)
[StructLayout(LayoutKind.Sequential)]
public struct INPUT_RECORD
{
public InputEventType EventType;
public EVENT_UNION Event;
}
But, I can't translate to vb.net.
Anyway, thanks for all your help.
Mark
Oopps... I didn't think about it. Well, I have another idea - in the
delegate method, call the WriteConsoleInput API function to write your
default value to the console input buffer.
/\/\/
Ok... I'm working on my Linux box again tonight - so I can't actually
test this code, but here is a translation of this structure :)
Imports System.Runtime.InteropServices
....
<Flags ()> _
Public Enum ControlKeyState
RightAltPressed = &H1
LeftAltPressed = &H2
RightCtrlPressed = &H4
LeftCtrlPressed = &H8
ShiftPressed = &H10
NumLockOn = &H20
ScrollLockOn = &H40
CapsLockOn = &H80
EnhancedKey = &H100
End Enum
<Flags ()> _
Public Enum MouseButtonState
FromLeft1stButtonPressed = &H1
RightMostButtonPressed = &H2
FromLeft2ndButtonPressed = &H4,
FromLeft3rdButtonPressed = &H8,
FromLeft4thButtonPressed = &H10,
End Enum
<Flags ()> _
Public Enum MouseEventFlags
MouseMoved = &H1
DoubleClick = &H2
MouseWheeled = &H4
End Enum
Public Enum InputEventType As Short
KeyEvent = &H1
MouseEvent = &H2
WindowBufferSizeEvent = &H4
MenuEvent = &H8
FocusEvent = &H10
End Enum
<StructLayout (LayoutKind.Sequential)> _
Public Structure COORD
Public X As Short
Public Y As Short
End Structure
<StructLayout (LayoutKind.Sequential)> _
Public Structure SMALL_RECT
Public Left As Short
Public Top As Short
Public Right As Short
Public Bottom As Short
End Structure
<StructLayout (LayoutKind.Explicit)> _
Public Structure CONSOLE_CHAR
<FieldOffset (0)> Public AsciiChar As Byte
<FieldOffset (0)> Public UnicodeChar As Short
End Structure
<StructLayout (LayoutKind.Sequential)> _
Public Structure KEY_EVENT_RECORD
Public bKeyDown As Boolean
Public wRepeatCount As Short
Public wVirtualKeyCode As Short
Public wVirtualScanCode As Short
Public uChar As CONSOLE_CHAR
Public dwControlKeyState As ControlKeyState
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure MOUSE_EVENT_RECORD
Public dwMousePosition As COORD
Public dwButtonState As MouseButtonState
Public dwControlKeyState As ControlKeyState
Public dwEventFlags As MouseEventFlags
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure WINDOW_BUFFER_SIZE_RECORD
Public dwSize As COORD
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure MENU_EVENT_RECORD
Public dwCommandId As Integer
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure FOCUS_EVENT_RECORD
Public bSetFocus As Boolean
End Structure
<StructLayout(LayoutKind.Explicit)> _
Public Structure EVENT_UNION
<FieldOffset(0)> Public KeyEvent As KEY_EVENT_RECORD
<FieldOffset(0)> Public MouseEvent As MOUSE_EVENT_RECORD
<FieldOffset(0)> Public WindowBufferSizeEvent As WINDOW_BUFFER_SIZE_RECORD
<FieldOffset(0)> Public MenuEvent As MENU_EVENT_RECORD
<FieldOffset(0)> Public FocusEvent As FOCUS_EVENT_RECORD
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure INPUT_RECORD
Public EventType As InputEventType
Public [Event] As EVENT_UNION
End Structure
Whoooh! Anyway, I think this should be pretty close. Let me know if
you have any problems.
--
Tom Shelton [MVP]