扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:EoS_3tion 来源:BLOG 2007年11月12日
关键字:
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.InteropServices; namespace WindowsApplication2 { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(49, 37); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(83, 12); this.label1.TabIndex = 0; this.label1.Text = "EoS.3tion制作"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(49, 64); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(65, 12); this.label2.TabIndex = 1; this.label2.Text = "使用方法:"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(65, 85); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(155, 12); this.label3.TabIndex = 2; this.label3.Text = "1、将序列号拷贝到剪切板。"; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(65, 107); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(179, 12); this.label4.TabIndex = 3; this.label4.Text = "2、将光标定位到序列号输入处。"; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(65, 128); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(77, 12); this.label5.TabIndex = 4; this.label5.Text = "3、按F10键。"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "SN输入工具(C#版Version0.1)"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } [DllImport("user32.dll", SetLastError=true)] public static extern bool RegisterHotKey( IntPtr hWnd, // handle to window int id, // hot key identifier KeyModifiers fsModifiers, // key-modifier options Keys vk // virtual-key code ); [DllImport("user32.dll", SetLastError=true)] public static extern bool UnregisterHotKey( IntPtr hWnd, // handle to window int id // hot key identifier ); [Flags()] public enum KeyModifiers { None = 0, Alt = 1, Control = 2, Shift = 4, Windows = 8 } private void ProcessHotkey()//主处理程序 { strKeys = Clipboard.GetText(); strKeys.Replace("-", "{TAB}"); SendKeys.Send(strKeys); } private Label label1; private Label label2; private Label label3; private Label label4; private Label label5; string strKeys; private void Form1_Load(object sender, System.EventArgs e) { label2.AutoSize = true; Clipboard.Clear();//先清空剪贴板防止剪贴板里面先复制了其他内容 RegisterHotKey(Handle, 100, 0, Keys.F10); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { UnregisterHotKey(Handle, 100);//卸载快捷键 } protected override void WndProc(ref Message m)//循环监视Windows消息 { const int WM_HOTKEY = 0x0312;//按快捷键 switch (m.Msg) { case WM_HOTKEY: ProcessHotkey();//调用主处理程序 break; } base.WndProc(ref m); } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者