SendKeys.Send メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)



各キーは 1 つ以上の文字で表されます。1 文字のキーボード文字を指定するには、その文字自体を使用します。たとえば、文字 A を表すには、文字 "A" をメソッドに渡します。2 文字以上の文字を表すには、前の文字の後に追加する文字を付け加えます。文字 A、B、および C を表すには、パラメータに "ABC" を指定します。
プラス記号 (+)、カレット (^)、パーセント記号 (%)、ティルダ (~)、およびかっこ (( )) は、SendKeys で特別な意味を持ちます。これらの文字の 1 つを指定するには、その文字を中かっこ ({}) で囲みます。たとえば、プラス記号を指定する場合は "{+}" を使用します。中かっこ文字を指定する場合は、"{{}" および "{}}" を使用します。角かっこ ([ ]) は、SendKeys では特別な意味を持ちませんが、中かっこで囲む必要があります。ほかのアプリケーションでは、角かっこはダイナミック データ エクスチェンジ (DDE: Dynamic Data Exchange) が発生したときに特別な意味を持ちます。
![]() |
---|
ほかのアプリケーションをアクティブにするマネージ メソッドはありません。したがって、現在のアプリケーション内部でこのクラスを使用するか、または FindWindow や SetForegroundWindow などのネイティブ Windows メソッドを使用して、ほかのアプリケーションに強制的にフォーカスを移すことができます。 |

Send メソッドを使用する方法を次のコード例に示します。この例を実行するには、Button1 というボタンを配置した Form1 というフォームに次のコードを貼り付けます。必ずクリック イベントをこの例のイベント処理メソッドに関連付けるようにしてください。ボタン コントロールの TabIndex プロパティは 0 に設定する必要があります。この例を実行するときは、フォームをダブルクリックしてボタンのクリック イベントを発生させます。
' Clicking Button1 causes a message box to appear. Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show("Click here!") End Sub ' Use the SendKeys.Send method to raise the Button1 click event ' and display the message box. Private Sub Form1_DoubleClick(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.DoubleClick ' Send the enter key; since the tab stop of Button1 is 0, this ' will trigger the click event. SendKeys.Send("{ENTER}") End Sub
// Clicking Button1 causes a message box to appear. private void Button1_Click(System.Object sender, System.EventArgs e) { MessageBox.Show("Click here!"); } // Use the SendKeys.Send method to raise the Button1 click event // and display the message box. private void Form1_DoubleClick(object sender, System.EventArgs e) { // Send the enter key; since the tab stop of Button1 is 0, this // will trigger the click event. SendKeys.Send("{ENTER}"); }
private: // Clicking Button1 causes a message box to appear. void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { MessageBox::Show( "Click here!" ); } // Use the SendKeys.Send method to raise the Button1 click event // and display the message box. void Form1_DoubleClick( Object^ /*sender*/, System::EventArgs^ /*e*/ ) { // Send the enter key; since the tab stop of Button1 is 0, this // will trigger the click event. SendKeys::Send( "{ENTER}" ); }
// Clicking button1 causes a message box to appear. private void button1_Click(Object sender, System.EventArgs e) { MessageBox.Show("Click here!"); } //button1_Click // Use the SendKeys.Send method to trigger the button1 click event // and display the message box. private void Form1_DoubleClick(Object sender, System.EventArgs e) { // Send the enter key; since the tab stop of button1 is 0, this // will trigger the click event. SendKeys.Send("{ENTER}"); } //Form1_DoubleClick


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSendKeys.Send メソッドを検索する場合は、下記のリンクをクリックしてください。

- SendKeys.Send メソッドのページへのリンク