• 自动输入QQ密码


    想做个登陆器,一来,不用保存密码到本地防止他人使用,二来,也省去输入密码

    输入QQ号就不说了,简单得很,主要是密码,用sendmessage或postmessage是绝对行不通的,只好模拟键盘了 用API   SendInput

    关键代码贴在这里,给自己备份

    代码
    private static string Lcase_s = "abcdefghijklmnopqrstuvwxyz`1234567890-=\\[];',./";
            
    private static string Ucase_s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+|{}:\"<>?";
            private static short[] KeyboardConstaint = new short[] { 6566676869707172737475767778798081828384858687888990
                ,
    0xC049505152535455565748 
                ,
    0xBD,0xBB,0xDC,0xDB,0xDD,0xBA,0xDE,0xBC,0xBE,0xBF};
            
            

            
    public static  bool  SendKeyCommand(string  key,IntPtr hwnd)
            {
                
    for (int i = 0; i < key.Length; i++)
                {
                    
    string ch = key.Substring(i,1);
                    
    int index = Lcase_s.IndexOf(ch);
                    
    //是否在正常下
                    if (index >= 0)
                    {
                        
    short mykey = KeyboardConstaint[index];
                        Thread.Sleep(
    1);
                        SetFocus(hwnd);
                        SendKeyDown(mykey);
                        SendKeyUp(mykey);
                    }
                    
    else
                    {
                        index 
    = Ucase_s.IndexOf(ch);
                        
    if (index >= 0)
                        {

                            
    short mykey = KeyboardConstaint[index];
                            Thread.Sleep(
    1);
                            SetFocus(hwnd);
                            SendKeyDown(VK_SHIFT);                        
                            SendKeyDown(mykey);
                            SendKeyUp(mykey);
                            SendKeyUp(VK_SHIFT);
                        }
                        
    else
                        {
                            
    return false;
                        }
                    }

                }
                
    return true;

            }

            
    public static void SendKeyDown(short key)
            {
                 
                Input[] input 
    = new Input[1];
                input[
    0].type = INPUT.KEYBOARD;
                input[
    0].ki.wVk = key;
                input[
    0].ki.time = GetTickCount();

                
    if (SendInput((uint)input.Length, input, Marshal.SizeOf(input[0])) < input.Length)
                {
                    
    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }

            
    public static void SendKeyUp(short key)
            {
                Input[] input 
    = new Input[1];
                input[
    0].type = INPUT.KEYBOARD;
                input[
    0].ki.wVk = key;
                input[
    0].ki.dwFlags = KEYEVENTF_KEYUP;
                input[
    0].ki.time = GetTickCount();

                
    if (SendInput((uint)input.Length, input, Marshal.SizeOf(input[0])) < input.Length)
                {
                    
    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
  • 相关阅读:
    L3-013. 非常弹的球
    L2-020. 功夫传人
    L1-039. 古风排版
    Innobackup备份过程
    MySQL物理备份的过程
    数据库表设计
    MySQL启动排错
    redo的类型和作用
    描述undo的三个作用
    redo log和binlog的纠缠
  • 原文地址:https://www.cnblogs.com/szyicol/p/1744579.html
Copyright © 2020-2023  润新知