SendKeys

G

Guest

Hi All,

I am developing an application using C#. The task that I would like to
perform can be achieved by using the SendKeys class. I had a read about the
SendKeys.Send method. It said that Windows CE was a supported OS but the API
didn't have the PDA icon. So it seems that SendKeys.Send() is not available
to .NET CF. Is there anything beside the OpenNETCF Smart Device Framework
that I can use to do this task using the .NET CF and Windows Embedded CE 6.0?


Thanks,
 
K

Kay-Christian Wessel

Here is something I use :

Kay



Const VK_SHIFT As Integer = &H10

Const KEYEVENTF_EXTENDEDKEY As Integer = &H1

Const KEYEVENTF_KEYUP As Integer = &H2

Const KEYEVENTF_SILENT As Integer = &H4

' private const int VK_LBUTTON = 01;

' private const int VK_RBUTTON = 02;

' private const int VK_CANCEL = 03;

' private const int VK_MBUTTON = 04 ;

' /* NOT contiguous with L & RBUTTON */

' private const int VK_BACK = 08;

' private const int VK_TAB = 09;

' private const int VK_CLEAR = 12;

' private const int VK_RETURN = 13;

' private const int VK_SHIFT = 16;

' private const int VK_CONTROL = 17;

' private const int VK_MENU = 18;

' private const int VK_PAUSE = 19;

' private const int VK_CAPITAL = 20;

' private const int VK_ESCAPE = 27;

' private const int VK_SPACE = 32;

' private const int VK_PRIOR = 33;

' private const int VK_NEXT = 34;

' private const int VK_END = 35;

' private const int VK_HOME = 36;

' private const int VK_LEFT = 37;

' private const int VK_UP = 38;

' private const int VK_RIGHT = 39;

' private const int VK_DOWN = 40;

' private const int VK_SELECT = 21;

' private const int VK_PRINT = 42;

' private const int VK_EXECUTE = 43;

' private const int VK_SNAPSHOT = 44;

' private const int VK_INSERT = 45;

' private const int VK_DELETE = 46;

' private const int VK_HELP = 47;

' /* VK_0 thru VK_9 are the same as

'ASCII '0' thru '9' (= 30 - = 39) */

' /* VK_A thru VK_Z are the same as

'ASCII 'A' thru 'Z' (= 41 - = 5A) */

' private const int VK_LWIN = 91;

' private const int VK_RWIN = 92;

' private const int VK_APPS = 93;

' private const int VK_NUMPAD0 = 96;

' private const int VK_NUMPAD1 = 97;

' private const int VK_NUMPAD2 = 97;

' private const int VK_NUMPAD3 = 98;

' private const int VK_NUMPAD4 = 99;

' private const int VK_NUMPAD5 = 100;

' private const int VK_NUMPAD6 = 101;

' private const int VK_NUMPAD7 = 102;

' private const int VK_NUMPAD8 = 103;

' private const int VK_NUMPAD9 = 104;

' private const int VK_MULTIPLY = 105;

' private const int VK_ADD = 106;

' private const int VK_SEPARATOR = 107;

' private const int VK_SUBTRACT = 108;

' private const int VK_DECIMAL = 109;

' private const int VK_DIVIDE = 110;

' private const int VK_F1 = 111;

' private const int VK_F2 = 113;

' private const int VK_F3 = 114;

' private const int VK_F4 = 115;

' private const int VK_F5 = 116;

' private const int VK_F6 = 117;

' private const int VK_F7 = 118;

' private const int VK_F8 = 119;

' private const int VK_F9 = 120;

' private const int VK_F10 = 121;

' private const int VK_F11 = 122;

' private const int VK_F12 = 123;

' private const int VK_F13 = 124;

' private const int VK_F14 = 125;

' private const int VK_F15 = 126;

' private const int VK_F16 = 127;

' private const int VK_F17 = 128;

' private const int VK_F18 = 129;

' private const int VK_F19 = 130;

' private const int VK_F20 = 131;

' private const int VK_F21 = 132;

' private const int VK_F22 = 133;

' private const int VK_F23 = 134;

' private const int VK_F24 = 135;

' private const int VK_NUMLOCK = 144;

' private const int VK_SCROLL = 145;



<DllImport("coredll")> _

Public Shared Sub keybd_event(ByVal vk As Byte, ByVal sc As Byte, ByVal
Flags As Integer, ByVal dwExtraInfo As Integer)

End Sub



Private Sub SendStringAsKeypress(ByVal strCh As String)

Dim ch As Char

Dim bytCh As Byte

ch = Convert.ToChar(strCh)

bytCh = BitConverter.GetBytes(ch)(0)

If bytCh > 64 And bytCh < 94 Then

keybd_event(VK_SHIFT, 0, 0, 0)

SendChar(bytCh)

keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0)

Else

SendChar(bytCh)

End If

End Sub



Public Sub SendChar(ByVal vk As Byte)

keybd_event(vk, 0, 0, 0)

keybd_event(vk, 0, KEYEVENTF_KEYUP, 0)

End Sub
 
G

Guest

Thanks for the reply. I should have been clearer. This would work when
sending a key to an application. I am trying to send the key to specific
controls. Any ideas as to how this could be done?

Thanks heaps,
 
P

Paul G. Tobey [eMVP]

Make sure that the control has the focus and use the code indicated. You
can't really expect the OS to continue working right if you're going to
bypass the input system when directing keyboard data. If you want to
experiment, you can pass a window handle to PostKeybdMessage()...

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top