国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
c#虛擬鍵盤、虛擬鼠標(biāo)以及窗口查找 - 唐朝程序員 - 博客園
我想編制一個(gè)qq自動(dòng)登陸程序,確發(fā)現(xiàn)C#中對(duì)很多api沒有封裝,只有使用平臺(tái)調(diào)用了。其中用到窗體查找和虛擬鍵盤、虛擬鼠標(biāo)等函數(shù)。具體代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace SimulateMouse
{
    
public partial class DemoForm : Form
    
{
        [StructLayout(LayoutKind.Sequential)]
        
struct NativeRECT
        
{
            
public int left;
            
public int top;
            
public int right;
            
public int bottom;
        }


        [Flags]
        
enum MouseEventFlag : uint
        
{
            Move        
= 0x0001,
            LeftDown    
= 0x0002,
            LeftUp      
= 0x0004,
            RightDown   
= 0x0008,
            RightUp     
= 0x0010,
            MiddleDown  
= 0x0020,
            MiddleUp    
= 0x0040,
            XDown       
= 0x0080,
            XUp         
= 0x0100,
            Wheel       
= 0x0800,
            VirtualDesk 
= 0x4000,
            Absolute    
= 0x8000
        }


        [DllImport(
"user32.dll")]
        
static extern bool SetCursorPos(int X, int Y);  

        [DllImport(
"user32.dll")]
        
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);

        [DllImport(
"user32.dll")]
        
static extern IntPtr FindWindow(string strClass, string strWindow);

        [DllImport(
"user32.dll")]
        
static extern IntPtr FindWindowEx(HandleRef hwndParent, HandleRef hwndChildAfter, string strClass, string strWindow);

        [DllImport(
"user32.dll")]
        
static extern bool GetWindowRect(HandleRef hwnd, out NativeRECT rect);
        [DllImport(
"user32.dll")]
        
static extern void keybd_event(byte bVk,byte bScan,uint dwFlags,uint dwExtraInfo);
        
private Point endPosition;

        
public DemoForm()
        
{
            InitializeComponent();
        }


               
private void button1_Click(object sender, EventArgs e)
        
{
            NativeRECT rect;

            IntPtr ptrTaskbar 
= FindWindow("#32770","QQ用戶登錄");
            
if (ptrTaskbar == IntPtr.Zero)
            
{
                MessageBox.Show(
"No taskbar found.");
                
return;
            }


            IntPtr ptrStartBtn 
= FindWindowEx(new HandleRef(this, ptrTaskbar), new HandleRef(this, IntPtr.Zero), "ComboBox"null);
            
if (ptrStartBtn == IntPtr.Zero)
            
{
                MessageBox.Show(
"No qq號(hào)碼框 found.");
                
return;
            }


            GetWindowRect(
new HandleRef(this, ptrStartBtn), out rect);

            endPosition.X 
= (rect.left + rect.right) / 2;
            endPosition.Y 
= (rect.top + rect.bottom) / 2;

            SetCursorPos(endPosition.X, endPosition.Y);
            mouse_event(MouseEventFlag.LeftDown, 
000, UIntPtr.Zero);
            mouse_event(MouseEventFlag.LeftUp, 
000, UIntPtr.Zero);
            mouse_event(MouseEventFlag.LeftDown, 
000, UIntPtr.Zero);
            mouse_event(MouseEventFlag.LeftUp, 
000, UIntPtr.Zero);


           

           System.IO.StreamWriter tw 
= new System.IO.StreamWriter(@"d:/aa.txt");
           tw.Write(
"49593533");
           tw.Close();

           System.IO.StreamReader tr 
= new System.IO.StreamReader(@"d:/aa.txt");
           String mystr 
= tr.ReadToEnd();
           tr.Close();

           
for(int i=0;i<mystr.Length;i++)
           keybd_event((
byte)mystr[i], 000);

       IntPtr ptrPassWord 
= FindWindowEx(new HandleRef(this, ptrTaskbar), new HandleRef(this, IntPtr.Zero), "#32770"null);
       GetWindowRect(
new HandleRef(this, ptrPassWord), out rect);

       endPosition.X 
= (rect.left + rect.right) / 2;
       endPosition.Y 
= (rect.top + rect.bottom) / 2;

       SetCursorPos(endPosition.X, endPosition.Y);
       mouse_event(MouseEventFlag.LeftDown, 
000, UIntPtr.Zero);
       mouse_event(MouseEventFlag.LeftUp, 
000, UIntPtr.Zero);
       mouse_event(MouseEventFlag.LeftDown, 
000, UIntPtr.Zero);
       mouse_event(MouseEventFlag.LeftUp, 
000, UIntPtr.Zero);


       mystr 
= "mypassword";
       
for (int i = 0; i < mystr.Length; i++)
       
{
          keybd_event((
byte)mystr[i], 000);
       }


        }

    }

}


說明:(
1)所有虛擬鍵盤碼可以到http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp去查找。

2)首先介紹一下Keybd_event函數(shù)。Keybd_event能觸發(fā)一個(gè)按鍵事件,也就是說回產(chǎn)生一個(gè)WM_KEYDOWN或WM_KEYUP消息。當(dāng)然也可以用產(chǎn)生這兩個(gè)消息來(lái)模擬按鍵,但是沒有直接用這個(gè)函數(shù)方便。Keybd_event共有四個(gè)參數(shù),第一個(gè)為按鍵的虛擬鍵值,如回車鍵為vk_return, tab鍵為vk_tab。第二個(gè)參數(shù)為掃描碼,一般不用設(shè)置,用0代替就行第三個(gè)參數(shù)為選項(xiàng)標(biāo)志,如果為keydown則置0即可,如果為keyup則設(shè)成“KEYEVENTF_KEYUP”或者2,第四個(gè)參數(shù)一般也是置0即可。

keybd_event(VK_CONTROL, (BYTE)
00 ,0);
keybd_event(
'A',(BYTE)00 ,0); //此處可以用 'A', (BYTE)65, 用'a'不起作用.
keybd_event('A', (BYTE)0, KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL, (BYTE)
0, KEYEVENTF_KEYUP,0);

上面的代碼表示 ctl
+a
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C# 鼠標(biāo)Win32 API定位、點(diǎn)擊、復(fù)位
在Winform中嵌入exe程序
golang彈出消息框
intptr
nginx 源碼學(xué)習(xí)筆記(六)——nginx基本數(shù)據(jù)結(jié)構(gòu)
C語(yǔ)言指針的長(zhǎng)度和類型深入分析
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服