吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6686|回复: 7
收起左侧

[其他原创] [C#]模拟按键工具

[复制链接]
os51 发表于 2016-11-25 17:58
本帖最后由 os51 于 2016-12-14 14:21 编辑

注意:此gui工具是用来绕过一些令人恶心的粘贴限制的,如果需要类似按键精灵的功能请转向 --->延时输入工具(http://www.52pojie.cn/thread-522703-1-1.html)
编译参数:csc /t:winexe
具体命令:(任何一个都可以,假设代码存储为SendkeysApp.cs)
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc /t:winexe SendkeysApp.cs
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /t:winexe SendkeysApp.cs
C:\Windows\Microsoft.NET\Framework64\v3.5\csc /t:winexe SendkeysApp.cs
C:\Windows\Microsoft.NET\Framework\v3.5\csc /t:winexe SendkeysApp.cs
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\csc /t:winexe SendkeysApp.cs
C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc /t:winexe SendkeysApp.cs
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace SendkeysApp
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
    
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.textBox1.Focus();
            this.Visible = false;
            int t = (int)(numericUpDown1.Value * 1000);
            System.Threading.Thread.Sleep(t);
            System.Windows.Forms.SendKeys.SendWait(textBox1.Text.Replace("\r\n", "{ENTER}"));
            this.Visible = true;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_ResizeEnd(object sender,EventArgs e)
        {
            textBox1.Width = this.ClientSize.Width - 24;
            textBox1.Height = this.ClientSize.Height - 51;
            button1.Left = this.ClientSize.Width - 87;
            button1.Top = this.ClientSize.Height - 33;
            button2.Left = this.ClientSize.Width - 141;
            button2.Top = this.ClientSize.Height - 33;
            label1.Top = this.ClientSize.Height - 31;
            numericUpDown1.Top = this.ClientSize.Height - 33;
            this.button3.Location = new System.Drawing.Point(this.ClientSize.Width - 188, this.ClientSize.Height - 33);
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.ReadOnly = false;
            button1.Enabled = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.ReadOnly = true;
            button1.Enabled = false;
            textBox1.Text = "按Clear按钮返回正常状态。\r\n要指定在按键(如 Enter 或 Tab)时不显示的字符,以及表示操作而不表示字符的键,请使用下表中的代码。\r\n键\t代码\r\nBackspace\t{BACKSPACE}、{BS} 或 {BKSP}\r\nBreak\t{BREAK}\r\nCaps Lock\t{CAPSLOCK}\r\nDel 或 Delete\t{DELETE} 或 {DEL}\r\n向下键\t{DOWN}\r\nEnd\t{END}\r\nEnter\t{ENTER} 或 ~\r\nEsc\t{ESC}\r\nHelp\t{HELP}\r\nHome\t{HOME}\r\nIns 或 Insert\t{INSERT} 或 {INS}\r\n向左键\t{LEFT}\r\nNum Lock\t{NUMLOCK}\r\nPage Down\t{PGDN}\r\n向上翻页\t{PGUP}\r\nPrint Screen\t{PRTSC}(保留供将来使用)\r\n向右键\t{RIGHT}\r\nScroll Lock\t{SCROLLLOCK}\r\nTAB\t{TAB}\r\n向上键\t{UP}\r\nF1\t{F1}\r\nF2\t{F2}\r\nF3\t{F3}\r\nF4\t{F4}\r\nF5\t{F5}\r\nF6\t{F6}\r\nF7\t{F7}\r\nF8\t{F8}\r\nF9\t{F9}\r\nF10\t{F10}\r\nF11\t{F11}\r\nF12\t{F12}\r\nF13\t{F13}\r\nF14\t{F14}\r\nF15\t{F15}\r\nF16\t{F16}\r\n数字键盘加号\t{ADD}\r\n数字键盘减号\t{SUBTRACT}\r\n数字键盘乘号\t{MULTIPLY}\r\n数字键盘除号\t{DIVIDE}\r\n要指定与 Shift、Ctrl 和 Alt 键的任意组合一起使用的键,请在这些键代码之前加上以下一段或多段代码。\r\n键\t代码\r\nShift\t+\r\nCtrl\t^\r\nAlt\t%\r\n要指定在按一些键时应同时按住 Shift、Ctrl 和 Alt 键的任意组合,请将这些键的代码放在括号内。 例如,要指定按 E 和 C 时同时按住 Shift 键,请使用“+(EC)”。 要指定按 E 时应按住 Shift,之后按 C 时不按住 Shift,请使用“+EC”。\r\n要指定重复键,请使用格式 {key number}。 键和数字之间必须放一空格。 例如,{LEFT 42} 表示按向左键 42 次;{h 10} 表示按 H 10 次";
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
            {
                ((TextBox)sender).SelectAll();
            }
            else if (e.Control & e.KeyCode == Keys.Back)
            {
                SendKeys.SendWait("^+{LEFT}{BACKSPACE}");
            }
        }
    }
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
            this.label1 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(12, 12);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBox1.Size = new System.Drawing.Size(367, 233);
            this.textBox1.TabIndex = 0;
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            this.textBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyUp);
            // 
            // numericUpDown1
            // 
            this.numericUpDown1.Location = new System.Drawing.Point(113, 254);
            this.numericUpDown1.Name = "numericUpDown1";
            this.numericUpDown1.Size = new System.Drawing.Size(39, 21);
            this.numericUpDown1.TabIndex = 1;
            this.numericUpDown1.Tag = "s";
            this.numericUpDown1.Value = new decimal(new int[] {
            2,
            0,
            0,
            0});
            this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 256);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(95, 12);
            this.label1.TabIndex = 2;
            this.label1.Text = "Delay(seconds):";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(304, 251);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 3;
            this.button1.Text = "SendKeys";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.button2.Location = new System.Drawing.Point(250, 251);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(48, 23);
            this.button2.TabIndex = 4;
            this.button2.Text = "Clear";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(203, 251);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(41, 23);
            this.button3.TabIndex = 5;
            this.button3.Text = "Help";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.button2;
            this.ClientSize = new System.Drawing.Size(391, 286);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.numericUpDown1);
            this.Controls.Add(this.textBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
            this.KeyPreview = true;
            this.Name = "Form1";
            this.ShowIcon = false;
            this.Text = "SendKeys实用程序";
            this.Load += new System.EventHandler(this.Form1_ResizeEnd);
            this.ResizeEnd += new System.EventHandler(this.Form1_ResizeEnd);
            this.Resize += new System.EventHandler(this.Form1_ResizeEnd);
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.NumericUpDown numericUpDown1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
    }
}
#s1.PNG
#s2.PNG

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ciaomi 发表于 2016-11-25 18:33
前排支持,表示新手还不知道怎么用
liyongji2016 发表于 2016-11-25 18:59
xiaodouble 发表于 2016-11-25 19:09
jackzhou158 发表于 2016-11-25 19:14
来看看,学习学习
psx1lin 发表于 2016-11-25 19:23
好文章

研究看看
a12138 发表于 2016-11-25 19:50
好像不会用啊,好厉害,存一下,希望以后能会
CSY_Cracker 发表于 2016-11-25 20:14
学习学习~
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-15 13:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表