VB's SendKeys and Remote Desktop

Hi!
Why is it that I can´t send keystrokes with VB6 "SendKeys" to Windows XP Remote Desktop? Works fine with every other window and apps except Remote Desktop. Anyone has the same experience? Solutions anyone?

/X_Ivar
X_IvarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mugman21Commented:
Never dealt with this before, given your description, it sound's like a security measure MS built in. Have you tried the spy utility to make sure your key strokes are being sent to the correct window?

Mugman
0
X_IvarAuthor Commented:
I use Appactivate so I can see that Remote Desktop is activated with Notepad on top before the SendKeys command is launched. I've also tried with differens kind of delays to be sure that for the window is activated before I use SendKeys. If I leave it like that and use the keyboard the characters will show in Notepad ok, but using VB's SendKeys just sends the characters to cyberspace. Sometimes I see that the Sendkeys command will disturb the caret's blink rate in Notepad on the other machine but that's all. Also if I use the Windows XP Screen keyboard it works. Why not the SendKeys command? I've searched for an api call to use instead and tried sendmessage but it doesn't work either.
0
IlanProdCommented:
You can try this:
1.use win32 API keyb_event, example:
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = &H2
Const
Private Sub SendKeyStroke()
keybd_event 27, 0, 0, 0
keybd_event 27, 0, KEYEVENTF_KEYUP, 0
End Sub

this should send an escape stroke...
just dont forget to call it again with the KEYEVENTF_KEYUP.

2.use win32 API SendMessage. example:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub SendKeyStroke2()
SendMessage hWnd,WM_KEYDOWN,27,0
End Sub

the hWnd you can get with FindWindow(http://www.mentalis.org/apilist/FindWindow.shtml) it's not that complicated...

hopefully the first one will work because he's the easiest one.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

X_IvarAuthor Commented:
IlanProd!

Your method 1 works (as VB's SendKeys) with other windows (like Notepad for example) but I can't make it work with XP's Remote Desktop. Do you? Also I changed 27 (Esc) to 65 (A) and that works just the same (although it sends lower case).

Method 2: I can't get that working at all, that is not with any window (although I've only tested Notepad). I can find the window handle but neither 27 or 65 is sent to the window. Same thing for Remote Desktop.

Furthermore I've realized that Remote Desktop is really a Terminal Services client - if that has something to do with anything.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
X_IvarAuthor Commented:
CAVrr!
Your link finally led me to a solution so I will accept it as an answer.

The followin code now works for my purposes:

Private Sub MySendKey(vKey As Long, KeyTypeAction As Long)
'* vKey is the virtual keycode I want to send
'* KeyTypeAction can be 0, KEYEVENTF_KEYUP or KEYEVENTF_EXTENDEDKEY
  Dim MyInput(1) As INPUT_TYPE
  Dim KeySent As KEYBDINPUT
    With KeySent
      .wVk = vKey And &HFF
      If (vKey = VK_SHIFT) Then
        .wScan = 42
      Else
        .wScan = MapVirtualKey(.wVk, 0)
      End If
      .dwFlags = KeyTypeAction
      .time = 0
      .dwExtraInfo = GetMessageExtraInfo
    End With
    MyInput(0).dwType = INPUT_KEYBOARD
    CopyMemory MyInput(0).xi(0), KeySent, Len(KeySent)
    SendInput 1, MyInput(0), Len(MyInput(0))
End Sub

0
CAVccCommented:
Great..  thought it might.  Glad it did.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.