SendKeys.Send メソッドとは? わかりやすく解説

SendKeys.Send メソッド

キーストロークアクティブアプリケーション送信します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

例外例外
例外種類条件

InvalidOperationException

キーストローク送信先となるアクティブアプリケーションはありません。

ArgumentException

keys有効なキーストローク表していません。

解説解説

キー1 つ上の文字表されます。1 文字キーボード文字指定するには、その文字自体使用します。たとえば、文字 A を表すには、文字 "A" をメソッド渡します。2 文字上の文字を表すには、前の文字の後に追加する文字付け加えます。文字 A、B、および C を表すには、パラメータに "ABC" を指定します

プラス記号 (+)、カレット (^)、パーセント記号 (%)、ティルダ (~)、およびかっこ (( )) は、SendKeys で特別な意味を持ちます。これらの文字1 つ指定するには、その文字中かっこ ({}) で囲みます。たとえば、プラス記号指定する場合は "{+}" を使用します中かっこ文字指定する場合は、"{{}" および "{}}" を使用します角かっこ ([ ]) は、SendKeys では特別な意味を持ちませんが、中かっこで囲む必要があります。ほかのアプリケーションでは、角かっこダイナミック データ エクスチェンジ (DDE: Dynamic Data Exchange) が発生したときに特別な意味を持ちます

注意に関するメモメモ

ほかのアプリケーションアクティブにするマネージ メソッドはありません。したがって現在のアプリケーション内部でこのクラス使用するか、または FindWindowSetForegroundWindow などのネイティブ 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
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

SendKeys.Send メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SendKeys.Send メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS