C# 向TIM或者QQ自动发送中文消息【微信也是可用的】 附测试GIF
生活随笔
收集整理的這篇文章主要介紹了
C# 向TIM或者QQ自动发送中文消息【微信也是可用的】 附测试GIF
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
之前用C++簡單的寫了一個demo
現在用C#寫了完整版
- 定義字符
- 定義發送數量
- 定義發送對象
注意事項
- QQ必須單獨一個窗體
- 微信對象在輸入名字的時候必須寫微信
源代碼
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace TimSendMessage {class Program{[DllImport("user32.dll")]static extern IntPtr FindWindow(String ClassName,String WindwosName);[DllImport("user32.dll")]static extern void keybd_event(byte vk,byte vsacn,int flag,int wram);[DllImport("user32.dll")]static extern void PostMessage(IntPtr hwnd,uint msg,int w,string l);[DllImport("user32.dll")]static extern void PostMessage(IntPtr hwnd, uint msg, int w, int l);[STAThread]static void Main(string[] args){Console.WriteLine("發送QQ的名字");var name = Console.ReadLine();Console.WriteLine("要發送的字符");var t = Console.ReadLine();Console.WriteLine("要發送的次數");var Count = int.Parse(Console.ReadLine());while(Count>-1){Thread.Sleep(TimeSpan.FromMilliseconds(50));Clipboard.SetText(t);SendKey(name,t);Count--;Console.WriteLine("測試次數"+Count);}}static void SendKey(string name,string l){var win= FindWindow(null, name);keybd_event(0x01, 0, 0, 0);//激活TIMPostMessage(win, 0x0302, 0, 0);// PostMessage(win, 0x0101, new Random().Next(65,128),0);//發送字符 //下面是發送回車PostMessage(win, 0x0100, 13, 0);PostMessage(win, 0x0101, 13, 0);keybd_event(0x11, 0, 0x0002, 0);}} }如果有哪位賢兄可以改成窗體也是不成問題的
源程序下載
轉載于:https://www.cnblogs.com/T-ARF/p/9471887.html
總結
以上是生活随笔為你收集整理的C# 向TIM或者QQ自动发送中文消息【微信也是可用的】 附测试GIF的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux驱动之内核加载模块过程分析
- 下一篇: [POJ3630] Phone List