Guest User

Untitled

a guest
Sep 21st, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5.  
  6.     namespace Keykey
  7.     {
  8.         public partial class Form1 : Form
  9.         {
  10.             public Form1()
  11.             {
  12.                 InitializeComponent();
  13.             }
  14.  
  15.             // Get a handle to an application window.
  16.             [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
  17.             public static extern IntPtr FindWindow(string lpClassName,
  18.                 string lpWindowName);
  19.  
  20.             // Activate an application window.
  21.             [DllImport("USER32.DLL")]
  22.             public static extern bool SetForegroundWindow(IntPtr hWnd);
  23.  
  24.             private void button1_Click(object sender, EventArgs e)
  25.             {
  26.                 // Get a handle to the Calculator application. The window class
  27.                 // and window name were obtained using the Spy++ tool.
  28.                 IntPtr calculatorHandle = FindWindow("CalcFrame", "Калькулятор");
  29.  
  30.                 // Verify that Calculator is a running process.
  31.                 if (calculatorHandle == IntPtr.Zero)
  32.                 {
  33.                     MessageBox.Show("Calculator is not running.");
  34.                     return;
  35.                 }
  36.  
  37.                 // Make Calculator the foreground application and send it
  38.                 // a set of calculations.
  39.                 SetForegroundWindow(calculatorHandle);
  40.                 SendKeys.SendWait("111");
  41.                 SendKeys.SendWait("*");
  42.                 SendKeys.SendWait("11");
  43.                 SendKeys.SendWait("=");
  44.             }
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment