Im trying to sendkeys to an remotedesktop using the interface IMsRdpClientNonScriptable (more info hereIMsRdpClientNonScriptable::SendKeys Method)
But somehow the AXIMP.exe fails to make the correct SendKeys method as defined by microsoft (see link above).
microsoft states that the sendkeys method should be native like this:
HRESULT SendKeys( [in] LONG numKeys, [in] VARIANT_BOOL *pbArrayKeyUp, [in] LONG *plKeyData );
I would argue that this correctly translated to C# would be like this:
int SendKeys(int numKeys, refbool[] pbArrayKeyUp, refint[] plKeyData)
But the AXIMP.EXE translates this into this:
void SendKeys(int numKeys, refbool pbArrayKeyUp, refint plKeyData);
I cant seem to get this to work. so I've been searing the web for a solution without success!!
I found that another guy had the same issue
aximp.exe generates incorrect wrapper method for IMsRdpClientNonScriptable::SendKeys but no solution was found here either. hmmm
OK so here ones and for all; "Does anyone have a working C# or VB.Net code that can send key strokes to the remote desktop. ???"
This code fails with the following (HRESULT E_FAIL at MSTSCLib.IMsRdpClientNonScriptable.SendKeys(Int32 numKeys, Boolean& pbArrayKeyUp, Int32& plKeyData)):
publicvoid SendKeys(IMsRdpClientNonScriptable rdpNonScript, Keys[] keys) {try {if (null != rdpNonScript) {int arrayIndex = 0;int[] plKeyData = newint[20];bool[] pbArrayKeyUp = newbool[20];for (int i = 0; i < keys.Length; i++) { plKeyData[arrayIndex] = (int)keys[i]; pbArrayKeyUp[arrayIndex] = false; arrayIndex++; }for (int i = keys.Length - 1; i >= 0; i--) { plKeyData[arrayIndex] = (int)keys[i]; pbArrayKeyUp[arrayIndex] = true; arrayIndex++; } rdpNonScript.SendKeys(keys.Length * 2, ref pbArrayKeyUp[0], ref plKeyData[0]); } }catch (Exception ex) { MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace); } }
With great code, comes great complexity, so keep it simple stupid...