当前位置:   article > 正文

C#之操作窗口模拟键鼠事件文件监控等知识使用

C#之操作窗口模拟键鼠事件文件监控等知识使用

C#之操作窗口模拟键鼠事件文件监控等知识使用

实现的效果图片,这里我在输入框输入一个号码,在C盘下创建一个文件txt文件,
被filewatch监控到,里面往指定窗口送sn被输入一些键盘鼠标的动作等操作;通过窗口句柄的操作发现窗口;
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
主要代码贴出来,

public partial class Form1 : Form
    {
   
        public Form1()
        {
   
            InitializeComponent();

            this.fileSystemWatcher1.Path = @"C:\ITF\XMLCEXPORT\";
        }



        //文件改变事件
        private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
        {
            string message = "文件:" + e.FullPath + " " + "改变于:" + DateTime.Now;
            if (!File.Exists("D:\\log.txt"))
            {
   
                FileStream fs1 = new FileStream("D:\\log.txt", FileMode.Create, FileAccess.Write);
                using (StreamWriter sw = new StreamWriter(fs1))
                {
   
                    sw.WriteLine(message);
                }
                // ||
                //StreamWriter sw = new StreamWriter(fs1);
                //sw.WriteLine(message);
                //sw.Close();
                fs1.Close();
            }
            else
            {
   
                FileStream fs2 = new FileStream("D:\\log.txt", FileMode.Append, FileAccess.Write);//FileMode.Append继续写入
                using (StreamWriter sw2 = new StreamWriter(fs2))
                {
   
                    sw2.WriteLine(message);
                }
                //StreamWriter sw2 = new StreamWriter(fs2);
                //sw2.WriteLine(message);
                //sw2.Close();
                fs2.Close();
            }
            //CopyDiretory(this.txtWatchFiles.Text.Trim(), this.txtGoalFiles.Text.Trim());
        }




        //文件创建事件
        private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
        {
   


            //FtpHelper ftpHelper = new FtpHelper(this.txtipAdd.Text.Trim(), this.txtUserName.Text.Trim(), this.txtPass.Text.Trim());

            string message = "文件:" + e.FullPath + " " + "创建与:" + DateTime.Now;
            Console.WriteLine(e.Name.ToString());
            Console.WriteLine(e.Name.ToString() + "=======哈哈哈");
            if (!File.Exists("D:\\log.txt"))
            {
   
                FileStream fs1 = new FileStream("D:\\log.txt", FileMode.Create, FileAccess.Write);
                using (StreamWriter sw = new StreamWriter(fs1))
                {
   
                    sw.WriteLine(message);
                }
                fs1.Close();
            }
            else
            {
   
                FileStream fs2 = new FileStream("D:\\log.txt", FileMode.Append, FileAccess.Write);
                using (StreamWriter sw2 = new StreamWriter(fs2))
                {
   
                    sw2.WriteLine(message);
                }
                fs2.Close();
            }
            //CopyDiretory(this.txtWatchFiles.Text.Trim(), this.txtGoalFiles.Text.Trim());
            //下载
            //ftpHelper.Download("java.rar", "D:\\java1.rar");
            //上传
            //FileInfo fileInfo = new FileInfo(e.FullPath.ToString());
            //Thread.Sleep(100);
            //string s = e.Name.ToString();
            //string lastname = s.Substring(s.LastIndexOf('.'));
            //string firsts = s.Substring(0, s.LastIndexOf('.'));
            //string dataName = DateTime.Now.ToString("mmddss");
            //string finalName = firsts + "_" + dataName + lastname;

            //string ftpath = DateTime.Now.ToString("yyyyMMdd");

            //ftpHelper.Upload(fileInfo, "\\" + ftpath + "\\" + finalName);
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/272485
推荐阅读
相关标签
  

闽ICP备14008679号