狮子头扣字软件C#重写版本
功能代码:
using System; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Forms; namespace shizi { public partial class Form1 : Form { private const int WM_HOTKEY = 0x0312; private const int ID_F8 = 9000; private const int ID_F7 = 2000; int count; int total = 0; bool switch1; string[] Returnlines; bool switch2; [DllImport("user32.dll")] private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk); [DllImport("user32.dll")] private static extern bool UnregisterHotKey(IntPtr hWnd, int id); public Form1() { InitializeComponent(); this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); } private void Form1_Load(object sender, EventArgs e) { RegisterHotKey(this.Handle, ID_F8, 0, (uint)Keys.F8); RegisterHotKey(this.Handle, ID_F7, 0, (uint)Keys.F7); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { UnregisterHotKey(this.Handle, ID_F8); UnregisterHotKey(this.Handle, ID_F7); } protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_HOTKEY && m.WParam.ToInt32() == ID_F8) { if (textBox_路径.Text == "") { MessageBox.Show("请先导入词汇后再进行操作"); return; } if (switch1 == true) { switch1 = false; return; } if (switch1 == false) { switch1 = true; initiateAsync(); return; } } if (m.Msg == WM_HOTKEY && m.WParam.ToInt32() == ID_F7) { if (switch2 == true) { switch2 = false; this.Hide(); return; } if (switch2 == false) { switch2 = true; this.Show(); return; } } } private async Task initiateAsync() { Random random = new Random(); int min = int.Parse(textBox_毫秒.Text); int max = int.Parse(textBox_毫秒1.Text); int randomNumber = random.Next(min, max + 1); count = int.Parse(textBox_行.Text); while(1+1==2) { char[] Returntext = Returnlines[count].ToCharArray(); for (int a = 0; a < Returntext.Length; a++) { SendKeys.Send(Returntext[a].ToString()); await Task.Delay(randomNumber); } if (comboBox_发送.SelectedIndex == 0) { SendKeys.Send("{ENTER}"); } else if (comboBox_发送.SelectedIndex == 1) { SendKeys.Send("^{ENTER}"); } if (checkBox_行.Checked == true) { count++; } else { count++; if (count >= total) { switch1 = false; break; } } textBox_运行行.Text = count.ToString(); textBox_行.Text = count.ToString(); if (count >= Returnlines.Length) { count = 0; } if (switch1 == false) { break; } Application.DoEvents(); } } private void button_导入_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"; openFileDialog.Multiselect = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { foreach (string file in openFileDialog.FileNames) { textBox_路径.Text = file; string filePath = textBox_路径.Text; string content = File.ReadAllText(filePath); Returnlines = content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); total = Returnlines.Length; textBox_总行.Text = Returnlines.Length.ToString(); } } } private void button_软件介绍_Click(object sender, EventArgs e) { MessageBox.Show("本款软件为c#重构版本f8为启动/关闭----f7隐藏/显示", "软件介绍"); } } }
页面代码:
namespace shizi { 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() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button_软件介绍 = new System.Windows.Forms.Button(); this.comboBox_发送 = new System.Windows.Forms.ComboBox(); this.checkBox_行 = new System.Windows.Forms.CheckBox(); this.label7 = new System.Windows.Forms.Label(); this.textBox_行 = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.textBox_毫秒1 = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.textBox_毫秒 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.button_导入 = new System.Windows.Forms.Button(); this.textBox_路径 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.textBox_运行行 = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.textBox_总行 = new System.Windows.Forms.TextBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.button_软件介绍); this.groupBox1.Controls.Add(this.comboBox_发送); this.groupBox1.Controls.Add(this.checkBox_行); this.groupBox1.Controls.Add(this.label7); this.groupBox1.Controls.Add(this.textBox_行); this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.label5); this.groupBox1.Controls.Add(this.textBox_毫秒1); this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.textBox_毫秒); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.button_导入); this.groupBox1.Controls.Add(this.textBox_路径); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Location = new System.Drawing.Point(2, 2); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(277, 144); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "设置"; // // button_软件介绍 // this.button_软件介绍.Location = new System.Drawing.Point(135, 112); this.button_软件介绍.Name = "button_软件介绍"; this.button_软件介绍.Size = new System.Drawing.Size(123, 23); this.button_软件介绍.TabIndex = 14; this.button_软件介绍.Text = "软件介绍"; this.button_软件介绍.UseVisualStyleBackColor = true; this.button_软件介绍.Click += new System.EventHandler(this.button_软件介绍_Click); // // comboBox_发送 // this.comboBox_发送.FormattingEnabled = true; this.comboBox_发送.Items.AddRange(new object[] { "Enter发送", "Ctrl+Enter发送"}); this.comboBox_发送.Location = new System.Drawing.Point(8, 114); this.comboBox_发送.Name = "comboBox_发送"; this.comboBox_发送.Size = new System.Drawing.Size(121, 20); this.comboBox_发送.TabIndex = 13; this.comboBox_发送.Text = "Enter发送"; // // checkBox_行 // this.checkBox_行.AutoSize = true; this.checkBox_行.Checked = true; this.checkBox_行.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox_行.Location = new System.Drawing.Point(138, 90); this.checkBox_行.Name = "checkBox_行"; this.checkBox_行.Size = new System.Drawing.Size(120, 16); this.checkBox_行.TabIndex = 12; this.checkBox_行.Text = "运行完回到第一行"; this.checkBox_行.UseVisualStyleBackColor = true; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(94, 92); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(41, 12); this.label7.TabIndex = 11; this.label7.Text = "行开始"; // // textBox_行 // this.textBox_行.Location = new System.Drawing.Point(45, 87); this.textBox_行.Name = "textBox_行"; this.textBox_行.Size = new System.Drawing.Size(43, 21); this.textBox_行.TabIndex = 10; this.textBox_行.Text = "0"; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(10, 91); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(29, 12); this.label6.TabIndex = 9; this.label6.Text = "从第"; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(185, 65); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(29, 12); this.label5.TabIndex = 8; this.label5.Text = "毫秒"; // // textBox_毫秒1 // this.textBox_毫秒1.Location = new System.Drawing.Point(138, 61); this.textBox_毫秒1.Name = "textBox_毫秒1"; this.textBox_毫秒1.Size = new System.Drawing.Size(43, 21); this.textBox_毫秒1.TabIndex = 7; this.textBox_毫秒1.Text = "30"; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(121, 67); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(11, 12); this.label4.TabIndex = 6; this.label4.Text = "-"; // // textBox_毫秒 // this.textBox_毫秒.Location = new System.Drawing.Point(71, 60); this.textBox_毫秒.Name = "textBox_毫秒"; this.textBox_毫秒.Size = new System.Drawing.Size(43, 21); this.textBox_毫秒.TabIndex = 5; this.textBox_毫秒.Text = "10"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(6, 66); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(59, 12); this.label3.TabIndex = 4; this.label3.Text = "按键间隔:"; // // button_导入 // this.button_导入.Location = new System.Drawing.Point(189, 32); this.button_导入.Name = "button_导入"; this.button_导入.Size = new System.Drawing.Size(75, 23); this.button_导入.TabIndex = 3; this.button_导入.Text = "导入"; this.button_导入.UseVisualStyleBackColor = true; this.button_导入.Click += new System.EventHandler(this.button_导入_Click); // // textBox_路径 // this.textBox_路径.Location = new System.Drawing.Point(13, 33); this.textBox_路径.Name = "textBox_路径"; this.textBox_路径.ReadOnly = true; this.textBox_路径.Size = new System.Drawing.Size(171, 21); this.textBox_路径.TabIndex = 2; // // label2 // this.label2.AutoSize = true; this.label2.ForeColor = System.Drawing.Color.Red; this.label2.Location = new System.Drawing.Point(123, 17); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(155, 12); this.label2.TabIndex = 1; this.label2.Text = "※请切换为智能ABC输入法!"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(10, 17); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(107, 12); this.label1.TabIndex = 0; this.label1.Text = "模拟扣字代码文件:"; // // groupBox2 // this.groupBox2.Controls.Add(this.textBox_运行行); this.groupBox2.Controls.Add(this.label8); this.groupBox2.Controls.Add(this.textBox_总行); this.groupBox2.Location = new System.Drawing.Point(3, 153); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(271, 58); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; this.groupBox2.Text = "运行信息"; // // textBox_运行行 // this.textBox_运行行.Location = new System.Drawing.Point(176, 24); this.textBox_运行行.Name = "textBox_运行行"; this.textBox_运行行.ReadOnly = true; this.textBox_运行行.Size = new System.Drawing.Size(89, 21); this.textBox_运行行.TabIndex = 6; // // label8 // this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(76, 28); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(101, 12); this.label8.TabIndex = 5; this.label8.Text = "总行数:运行位置:"; // // textBox_总行 // this.textBox_总行.Location = new System.Drawing.Point(6, 24); this.textBox_总行.Name = "textBox_总行"; this.textBox_总行.ReadOnly = true; this.textBox_总行.Size = new System.Drawing.Size(65, 21); this.textBox_总行.TabIndex = 3; // // Form1 // this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(283, 216); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "狮子头扣字软件"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button button_导入; private System.Windows.Forms.TextBox textBox_路径; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button_软件介绍; private System.Windows.Forms.ComboBox comboBox_发送; private System.Windows.Forms.CheckBox checkBox_行; private System.Windows.Forms.Label label7; private System.Windows.Forms.TextBox textBox_行; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox textBox_毫秒1; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox textBox_毫秒; private System.Windows.Forms.Label label3; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.TextBox textBox_运行行; private System.Windows.Forms.Label label8; private System.Windows.Forms.TextBox textBox_总行; } }
希望各位拿代码的可以保留1987版权,版权人by辰楠