Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
GeneralRe: managed c++ class that inherits from unmanaged c++ Pin
Heath Stewart11-Feb-04 10:10
protectorHeath Stewart11-Feb-04 10:10 
GeneralMouse Button > keystroke Pin
Spanky311-Feb-04 8:04
Spanky311-Feb-04 8:04 
GeneralRe: Mouse Button > keystroke Pin
Kentamanos11-Feb-04 8:15
Kentamanos11-Feb-04 8:15 
GeneralRe: Mouse Button > keystroke Pin
Daniel Turini11-Feb-04 8:16
Daniel Turini11-Feb-04 8:16 
GeneralRe: Mouse Button > keystroke Pin
Spanky311-Feb-04 8:28
Spanky311-Feb-04 8:28 
GeneralRe: Mouse Button > keystroke Pin
Kentamanos11-Feb-04 9:20
Kentamanos11-Feb-04 9:20 
GeneralRe: Mouse Button > keystroke Pin
Anonymous11-Feb-04 9:31
Anonymous11-Feb-04 9:31 
GeneralRe: Mouse Button > keystroke Pin
Kentamanos11-Feb-04 10:36
Kentamanos11-Feb-04 10:36 
Here's a chunk of code I wrote. This class was basically being hosted by remoting (thus the MarshalByRefObject), but it moves the mouse where you want it. It shows how to interop with SendInput (importing the definition and defining a few structures you'll need).


<div style="font-family:Courier New;font-size:10pt;background-color:#FFFFFF" >
<span style="color:#0000FF;">using </span><span style="color:#000000;">System;<br>
</span><span style="color:#0000FF;">using </span><span style="color:#000000;">System.Runtime.InteropServices;<br>
<br>
<br>
[StructLayout(LayoutKind.Explicit, Size=28)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">Input<br>
{<br>
  [FieldOffset (0)]<br>
  </span><span style="color:#0000FF;">public uint  </span><span style="color:#000000;">type;<br>
  [FieldOffset (4)]<br>
  </span><span style="color:#0000FF;">public </span><span style="color:#000000;">MouseInput mi;<br>
  [FieldOffset (4)]<br>
  </span><span style="color:#0000FF;">public </span><span style="color:#000000;">KeyboardInput ki;<br>
  [FieldOffset (4)]<br>
  </span><span style="color:#0000FF;">public </span><span style="color:#000000;">HardwareInput hi;<br>
<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">INPUT_MOUSE    = 0;<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">INPUT_KEYBOARD  = 1;<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">INPUT_HARDWARE  = 2;<br>
 }<br>
<br>
[StructLayout(LayoutKind.Sequential, Size=24)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">MouseInput<br>
{<br>
  </span><span style="color:#0000FF;">public int  </span><span style="color:#000000;">dx;<br>
  </span><span style="color:#0000FF;">public int  </span><span style="color:#000000;">dy;<br>
  </span><span style="color:#0000FF;">public uint  </span><span style="color:#000000;">mouseData;<br>
  </span><span style="color:#0000FF;">public uint  </span><span style="color:#000000;">dwFlags;<br>
  </span><span style="color:#0000FF;">public uint  </span><span style="color:#000000;">time;<br>
  </span><span style="color:#0000FF;">public uint  </span><span style="color:#000000;">dwExtraInfo;<br>
<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_MOVE      = 0x0001</span><span style="color:#008000;">/* mouse move */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_LEFTDOWN    = 0x0002</span><span style="color:#008000;">/* left button down */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_LEFTUP    = 0x0004</span><span style="color:#008000;">/* left button up */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_RIGHTDOWN    = 0x0008</span><span style="color:#008000;">/* right button down */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_RIGHTUP    = 0x0010</span><span style="color:#008000;">/* right button up */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_MIDDLEDOWN  = 0x0020</span><span style="color:#008000;">/* middle button down */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_MIDDLEUP    = 0x0040</span><span style="color:#008000;">/* middle button up */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_XDOWN      = 0x0080</span><span style="color:#008000;">/* x button down */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_XUP      = 0x0100</span><span style="color:#008000;">/* x button down */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_WHEEL      = 0x0800</span><span style="color:#008000;">/* wheel button rolled */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_VIRTUALDESK  = 0x4000</span><span style="color:#008000;">/* map to entire virtual desktop */<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_ABSOLUTE    = 0x8000</span><span style="color:#008000;">/* absolute move */<br>
</span><span style="color:#000000;">}<br>
<br>
[StructLayout(LayoutKind.Sequential, Size=24)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">KeyboardInput<br>
{<br>
  </span><span style="color:#0000FF;">public ushort  </span><span style="color:#000000;">wVk;<br>
  </span><span style="color:#0000FF;">public ushort  </span><span style="color:#000000;">wScan;<br>
  </span><span style="color:#0000FF;">public uint    </span><span style="color:#000000;">dwFlags;<br>
  </span><span style="color:#0000FF;">public uint    </span><span style="color:#000000;">time;<br>
  </span><span style="color:#0000FF;">public uint    </span><span style="color:#000000;">dwExtraInfo;<br>
<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_EXTENDEDKEY    = 0x0001;<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_KEYUP      = 0x0002;<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_UNICODE      = 0x0004;<br>
  </span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_SCANCODE    = 0x0008;<br>
}<br>
<br>
[StructLayout(LayoutKind.Sequential, Size=24)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">HardwareInput<br>
{<br>
  </span><span style="color:#0000FF;">public uint    </span><span style="color:#000000;">uMsg;<br>
  </span><span style="color:#0000FF;">public ushort  </span><span style="color:#000000;">wParamL;<br>
  </span><span style="color:#0000FF;">public ushort  </span><span style="color:#000000;">wParamH;<br>
}<br>
<br>
<br>
<br>
</span><span style="color:#0000FF;">namespace </span><span style="color:#000000;">InputSimulation<br>
{<br>
  </span><span style="color:#808080;">/// <summary><br>
  /// </span><span style="color:#008000;">Summary description for Class1.<br>
  </span><span style="color:#808080;">/// </summary><br>
<br>
  </span><span style="color:#0000FF;">public class </span><span style="color:#000000;">InputSimulation : MarshalByRefObject<br>
  {<br>
<br>
    [DllImport("user32.dll")]</span><span style="color:#0000FF;">public static extern uint </span><span style="color:#000000;">SendInput(</span><span style="color:#0000FF;">uint </span><span style="color:#000000;">nInputs, </span><span style="color:#0000FF;">ref </span><span style="color:#000000;">Input inputs, </span><span style="color:#0000FF;">int </span><span style="color:#000000;">sizeofInput);<br>
    <br>
    </span><span style="color:#0000FF;">public </span><span style="color:#000000;">InputSimulation()<br>
    {<br>
    }<br>
<br>
    </span><span style="color:#0000FF;">public void </span><span style="color:#000000;">MouseMove(</span><span style="color:#0000FF;">ushort </span><span style="color:#000000;">x, </span><span style="color:#0000FF;">ushort </span><span style="color:#000000;">y)<br>
    {<br>
      Input[] i = {</span><span style="color:#0000FF;">new </span><span style="color:#000000;">Input()};<br>
      i[0].type = 0;<br>
      i[0].mi.dx = (</span><span style="color:#0000FF;">int</span><span style="color:#000000;">) x;<br>
      i[0].mi.dy = (</span><span style="color:#0000FF;">int</span><span style="color:#000000;">) y;<br>
      i[0].mi.dwExtraInfo = 0;<br>
      i[0].mi.dwFlags = MouseInput.MOUSEEVENTF_ABSOLUTE | MouseInput.MOUSEEVENTF_MOVE | MouseInput.MOUSEEVENTF_VIRTUALDESK;<br>
      i[0].mi.mouseData = 0;<br>
      i[0].mi.time = 0;<br>
<br>
      </span><span style="color:#0000FF;">uint </span><span style="color:#000000;">ret = SendInput(1</span><span style="color:#0000FF;">ref </span><span style="color:#000000;">i[0], System.Runtime.InteropServices.Marshal.SizeOf(i[0]));<br>
    }<br>
<br>
    </span><span style="color:#0000FF;">public void </span><span style="color:#000000;">MouseClick()<br>
    {<br>
      Input[] i = {</span><span style="color:#0000FF;">new </span><span style="color:#000000;">Input(), </span><span style="color:#0000FF;">new </span><span style="color:#000000;">Input()};<br>
<br>
    }<br>
  }<br>
}<br>
</span>
</div> 




I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.

-David St. Hubbins
GeneralRe: Mouse Button &gt; keystroke Pin
Anonymous11-Feb-04 10:59
Anonymous11-Feb-04 10:59 
GeneralRe: Mouse Button &gt; keystroke Pin
Spanky311-Feb-04 11:16
Spanky311-Feb-04 11:16 
GeneralRe: Mouse Button > keystroke Pin
Kentamanos11-Feb-04 11:30
Kentamanos11-Feb-04 11:30 
GeneralRe: Mouse Button &gt; keystroke Pin
Spanky311-Feb-04 11:44
Spanky311-Feb-04 11:44 
GeneralRe: Mouse Button &gt; keystroke Pin
Kentamanos11-Feb-04 11:55
Kentamanos11-Feb-04 11:55 
GeneralRe: Mouse Button &gt; keystroke Pin
Spanky311-Feb-04 11:54
Spanky311-Feb-04 11:54 
GeneralNearly Sorted! Pin
Spanky311-Feb-04 12:02
Spanky311-Feb-04 12:02 
GeneralRe: Nearly Sorted! Pin
Spanky311-Feb-04 12:15
Spanky311-Feb-04 12:15 
GeneralRe: Nearly Sorted! Pin
Kentamanos11-Feb-04 12:18
Kentamanos11-Feb-04 12:18 
GeneralRe: Nearly Sorted! Pin
Spanky311-Feb-04 12:21
Spanky311-Feb-04 12:21 
QuestionHow do you do: On Explorer, right click on file -&gt; Open with...-&gt; MyApp.exe ? Pin
mdundek11-Feb-04 7:01
mdundek11-Feb-04 7:01 
AnswerRe: How do you do: On Explorer, right click on file -&gt; Open with...-&gt; MyApp.exe ? Pin
Heath Stewart11-Feb-04 9:43
protectorHeath Stewart11-Feb-04 9:43 
Questionhow to draw an X axis by datetime data! Pin
Member 185560811-Feb-04 4:23
Member 185560811-Feb-04 4:23 
AnswerRe: how to draw an X axis by datetime data! Pin
leppie11-Feb-04 6:05
leppie11-Feb-04 6:05 
GeneralComputer Info Pin
Kenneth Childs11-Feb-04 4:11
Kenneth Childs11-Feb-04 4:11 
GeneralRe: Computer Info Pin
hxxbin11-Feb-04 4:21
hxxbin11-Feb-04 4:21 
GeneralRe: Computer Info Pin
Kenneth Childs11-Feb-04 5:01
Kenneth Childs11-Feb-04 5:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.