大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Command1_Click() ReferForm "WebBrowser1", 2, "message", Text1.Text End Sub Private Sub Command2_Click() ReferForm "WebBrowser1", 8, "submit" End Sub Private Sub Form_Load() WebBrowser1.Navigate (" ") End Sub '************************************************************************* '**函 数 名:ReferForm '**中文意译:表单提交 '**输 入:ByVal WebbrowserA(String) - webbrowser控件名 '** :ByVal FormType(Integer) - 集合 表单类型 '** Text = 0; password = 1; textarea = 2; Hidden = 3; CheckBox = 4; submit = 8; button = 9 '** :Optional FormName(String) - 表单名[可选] '** :Optional Value(String = "") - 表单值[可选] '**输 出:无 '**功能描述: '** : '**作 者:最恨VB '**日 期:2008-01-31 07:46:14 '************************************************************************* Sub ReferForm(ByVal Webbrowser$, ByVal FormType%, Optional FormName$, Optional Value$ = "") If FormType 0 Or FormType 9 Then Exit Sub End If Dim objDoc, objTag Set objDoc = Me.Controls(Webbrowser).Document For i = 0 To objDoc.All.length - 1 Select Case UCase$(objDoc.All(i).tagName) Case "INPUT" Set objTag = objDoc.All(i) Select Case FormType Case 0, 1 If objTag.Name = FormName Then objTag.Value = Value End If Case 3 Case 4 If objTag.Name = FormName Then objTag.Click End If Case 8 If objTag.Type = FormName Then objTag.Click End If Case 9 If objTag.Typ
成都创新互联公司执着的坚持网站建设,小程序开发;我们不会转行,已经持续稳定运营10年。专业的技术,丰富的成功经验和创作思维,提供一站式互联网解决方案,以客户的口碑塑造品牌,携手广大客户,共同发展进步。
一、模拟键盘操作
以下示例程序当点击button1按钮,模拟键盘在文本框textBox1中作输入操作,详细说明请参看MSDN帮助中的SendKeys类。
//事件完整代码
private void button1_Click(object sender, System.EventArgs e)
{
this.textBox1.Focus(); //先必须让文本框得到焦点,因为焦点在button1上
SendKeys.Send("^a"); //Ctrl+A
SendKeys.Send("{DEL}"); //Delete
SendKeys.Send("+(ec)"); //Shift+"ec"
SendKeys.Send("{ENTER}"); //Enter
SendKeys.Send("+ec"); //Shift+'e'+'c'
SendKeys.Send("{ENTER}"); //Enter
SendKeys.Send("{h 10}"); //"hhhhhhhhhh"
SendKeys.Send("{ENTER}"); //Enter
SendKeys.Send("^%{DEL}"); //Alt+Ctrl+Del
}
二、模拟鼠标操作
以下示例程序当点击DBButton按钮,模拟鼠标双击窗体事件,并将鼠标向左上方移动10*10象素,其它操作类似。
//引入名字空间
using System.Runtime.InteropServices
//申明
[DllImport("user32")]
private static extern int mouse_event(int dwFlags,int dx,int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
//事件完整代码
private void Form_DoubleClick(object sender, System.EventArgs e)
{
MessageBox.Show("你双击了屏幕");
}
private void DBButton_Click(object sender, System.EventArgs e)
{
mouse_event(MOUSEEVENTF_MOVE,-10,-10,0,0); //移动鼠标,否则事件发生在按钮上
Down,Up合为一次单击事件
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
添加服务引用,然后调用HelloWorld方法,将数据以参数的形式传递给 HelloWorld
用API函数,以下代码Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Const WS_EX_LAYERED = H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = H2
Private Const LWA_COLORKEY = H1Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMosT = -1
Private Const SWP_NOMOVE = H2
Private Const SWP_NosIZE = H1
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_KEYDOWN = H100
Const WM_KEYUP = H101
Const WM_CHAR = H102
Const VK_F1 = H70
Private Sub SendF1(hwnd) '调用这个过程即可对目标窗体发送F1键
Call PostMessage(hwnd, WM_KEYDOWN, VK_F1, 0)
Call PostMessage(hwnd, WM_KEYUP, VK_F1, 0)
End Sub这里是发送F1的实例,各个按键对应的虚拟键码,要到网上查
看了很多这方便的解决方案,很多都是一大段代码,版本也有差别,既然有可能别人用得起我也用不起。
我用一种最简单的方法,只要思路对所有人都能用得起。
其实非常简单,就是获取键值,Ctrl+Enter的健值是10,是不是思路一下就通了。以下是源码:
Private Sub 聊天输入框_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 聊天输入框.KeyPress
If Asc(e.KeyChar) = 发送快捷键值 Then
发送消息过程()
End If
End Sub
源内容出处: