Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

A problem of Windows API

$
0
0

Hi friends:

It is the first time I ask for help here.

My problems is about windows API function. Below is my C# source code.When I click butten1 in windowsform1,I want the software to enter "windowers+R" and then release them, after enter "Enter". But when I run the software so many dialogue boxes come out. Please help me find out the mistakes in my code. Thanks so much.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace APItest { public partial class Form1 : Form { [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { keybd_event(91,0,0,0);//enter windkey keybd_event(82,0,0,0);//enter R keybd_event(91, 0, 2, 0);//release windows-key keybd_event(82, 0, 2, 0);//release R keybd_event(13, 0, 0, 0);//enter enter-key keybd_event(13, 0, 2, 0);//release enter-key } } }




Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>