SendKeys, how to use

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm tryng to send chars from my program to any other application directly
below (for example: Pocket Word) I use SendKeys. Send("...."); but there is
no result, the String is not sent to the application and there is no Error
message!
 
Could you show us some code? SendKeys just puts chars into the normal
keyboard input stream, so if Pocket Word is up and focused, it should get
the input.


--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
I've used this class in a normal windows project and, it's the same problem,
no char wrotten and no error message :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Description résumée de Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();

//
// TODO : ajoutez le code du constructeur après l'appel à
InitializeComponent
//
}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(184, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 16);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
SendKeys.Send("a");
}
}
}
 
Have you seen this virtual keys list:
http://msdn.microsoft.com/library/d...wsUserInterface/UserInput/VirtualKeyCodes.asp

Letter 'a' is 97 (0x61) and equals to VK_NUMPAD1

Try to send "A" instead and for more information about SendKeys see:
http://msdn2.microsoft.com/library/k3w7761b.aspx


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

I've used this class in a normal windows project and, it's the same problem,
no char wrotten and no error message :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Description résumée de Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();

//
// TODO : ajoutez le code du constructeur après l'appel à
InitializeComponent
//
}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(184, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 16);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
SendKeys.Send("a");
}
}
}
 
By the way, where is your textbox or something? In you test application
you are trying to send "A" to a button.

Place a textbox into the form, and before sending keys, set the focus to it:

private void button1_Click(object sender, System.EventArgs e)
{
newTextBox.Focus();
SendKeys.Send("A");
}

The same applies to Pocket Word or other applications; before invoke
SendKeys.Send you should activate this application that it will receive
the focus.



Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

I've used this class in a normal windows project and, it's the same problem,
no char wrotten and no error message :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Description résumée de Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();

//
// TODO : ajoutez le code du constructeur après l'appel à
InitializeComponent
//
}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(184, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 16);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
SendKeys.Send("a");
}
}
}
 
I found the problem but I don't know how to proceed: SendKeys.Send sends the
character to the active appication, and since it is my application which is
active it is it which receive the message which it sent, so I must use
FindWindow and SetForegroundWindow, but I don't know which name spaces I must
call especially in the CF.
 
I found the problem but I don't know how to proceed: SendKeys.Send sends the
character to the active appication, and since it is my application which is
active it is it which receive the message which it sent, so I must use
FindWindow and SetForegroundWindow, but I don't know which name spaces I must
call especially in the CF.
 
I have used them but the folowing error 'System.MissingMethodException' is
produced when trying to execute SetForegroundWindow(FindWindow("Form",null));
on the emulator
 
well, thanks for help, now the problem is how to find the title of opened
windows on our pocket PC; in your exemple the window title is fixed by a
String value, in my application I want it works with any window opened below
(Pocket Word, Messenger, calculator.... or any other application)
 
Back
Top