求VB.net 制作的软键盘“屏幕键盘”
我现在没有现成的代码给你,不过可以给你一些建议。如果你想在同一进程内实现屏幕键盘,则你只需要再F2打开的时候,将F1的当前焦点控件对象作为参数,传递给F2窗体,在F2点击屏幕控件时,设置该“控件.Text = 键值” 即可,这种我称之为假屏幕键盘。如果你想跨进程实现屏幕键盘,就比较难些了(比如:你想用你的F2窗体上的按键,实现QQ聊天内容的输入、记事本内容的输入)。这个需要用到 “键盘钩子”技术,有关这方面的资料,你不妨自己找找。 另外,你提的F2焦点老处理不好,我认为F2根本不需要焦点控件(不要用按钮做控件,而实用Label或图片就可以了。)
成都创新互联公司成立10多年来,这条路我们正越走越好,积累了技术与客户资源,形成了良好的口碑。为客户提供成都网站设计、成都网站建设、网站策划、网页设计、空间域名、网络营销、VI设计、网站改版、漏洞修补等服务。网站是否美观、功能强大、用户体验好、性价比高、打开快等等,这些对于网站建设都非常重要,成都创新互联公司通过对建站技术性的掌握、对创意设计的研究为客户提供一站式互联网解决方案,携手广大客户,共同发展进步。
VB调用API模拟键盘输入
简单点的可以用sendkeys,要模拟按键可以keybd_event,高级点的可以用sendmessage或者postmessage,我做了个自动喊话的,用的是sendkeys,下面是代码:
Private
Declare
Function
FindWindow
Lib
"user32"
Alias
"FindWindowA"
(ByVal
lpClassName
As
String,
ByVal
lpWindowName
As
String)
As
Long
'
Private
Declare
Function
GetForegroundWindow
Lib
"user32"
()
As
Long
'获得前台窗口的句柄
Private
Declare
Function
GetAsyncKeyState
Lib
"user32"
(ByVal
vKey
As
Long)
As
Integer
'
Private
Sub
Form_Load()
Timer1.Enabled
=
False
End
Sub
Private
Sub
Timer1_Timer()
Dim
a,
b
As
Long
Static
t
As
Integer
a
=
FindWindow(vbNullString,
"地下城与勇士")
b
=
GetForegroundWindow
If
a
=
b
Then
t
=
t
+
1
If
t
=
1
Then
SendKeys
"{ENTER}"
ElseIf
t
=
2
Then
SendKeys
"{/}"
ElseIf
t
=
3
Then
SendKeys
"{r}"
ElseIf
t
=
4
Then
SendKeys
"{e}"
ElseIf
t
=
5
Then
SendKeys
"{ENTER}"
t
=
End
If
End
If
End
Sub
Private
Sub
Timer2_Timer()
If
GetAsyncKeyState(vbKeyF9)
Then
Timer1.Enabled
=
True
ElseIf
GetAsyncKeyState(vbKeyF10)
Then
Timer1.Enabled
=
False
a
=
End
If
End
Sub
VB 怎么模拟键盘 输入,包括键盘的每一个健 TAB 也要?
tab是
"{TAB}".==========SendKeys
语句
将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样。语法SendKeys
string[,
wait]SendKeys
语句的语法具有以下几个命名参数:部分
描述
string
必需的。字符串表达式,指定要发送的按键消息。
Wait
可选的。指定等待方式的
BooleandefBooleanDataType@veendf98.chm
值。如果为
False(缺省值),则控件在按键发送出去之后立刻返回到过程。如果为
True,则按键消息必须在控件返回到过程之前加以处理。
说明每个按键由一个或多个字符表示。为了指定单一键盘字符,必须按字符本身的键。例如,为了表示字母
A,可以用
"A"
作为
string。为了表示多个字符,就必须在字符后面直接加上另一个字符。例如,要表示
A、B
及
C,可用
"ABC"
作为
string。对
SendKeys
来说,加号
(+)、插入符
(^)、百分比符号
(%)、上划线
(~)
及圆括号
(
)
都具有特殊意义。为了指定上述任何一个字符,要将它放在大括号
({})
当中。例如,要指定正号,可用
{+}
表示。方括号
([
])
对
SendKeys
来说并不具有特殊意义,但必须将它们放在大括号中。在其它应用程序中,方括号有特殊意义,在出现动态数据交换
(DDE)
的时候,它可能具有重要意义。为了指定大括号字符,请使用
{{}
及
{}}。为了在按下按键时指定那些不显示的字符,例如
ENTER
或
TAB
以及那些表示动作而非字符的按键,请使用下列代码:按键
代码
BACKSPACE
{BACKSPACE},
{BS},
或
{BKSP}
BREAK
{BREAK}
CAPS
LOCK
{CAPSLOCK}
DEL
or
DELETE
{DELETE}
或
{DEL}
DOWN
ARROW
{DOWN}
END
{END}
ENTER
{ENTER}或
~
ESC
{ESC}
HELP
{HELP}
HOME
{HOME}
INS
or
INSERT
{INSERT}
或
{INS}
LEFT
ARROW
{LEFT}
NUM
LOCK
{NUMLOCK}
PAGE
DOWN
{PGDN}
PAGE
UP
{PGUP}
SCREEN
{PRTSC}
RIGHT
ARROW
{RIGHT}
SCROLL
LOCK
{SCROLLLOCK}
TAB
{TAB}
UP
ARROW
{UP}
F1
{F1}
F2
{F2}
F3
{F3}
F4
{F4}
F5
{F5}
F6
{F6}
F7
{F7}
F8
{F8}
F9
{F9}
F10
{F10}
F11
{F11}
F12
{F12}
F13
{F13}
F14
{F14}
F15
{F15}
F16
{F16}
为了指定那些与
SHIFT、CTRL
及
ALT
等按键结合的组合键,可在这些按键码的前面放置一个或多个代码,这些代码列举如下:按键
代码
SHIFT
+
CTRL
^
ALT
%
为了说明在按下其它按键时应同时按下
SHIFT、CTRL、及
ALT
的任意组合键,请把那些按键的码放在括号当中。例如,为了说明按下
E
与
C
的时候同时按下
SHIFT
键,请使用
"+(EC)"。为了说明在按下
E
的时候同时按下
SHIFT
键,但接着按
C
而不按
SHIFT,则使用
"+EC"。为了指定重复键,使用
{key
number}
的形式。必须在
key
与
number
之间放置一个空格。例如,{LEFT
42}
意指
42
次按下
LEFT
ARROW
键;{h
10}
则是指
10
次按下
H
键。注意
不能用
SendKeys
将按键消息发送到这样一个应用程序,这个应用程序并没有被设计成在
Microsoft
Windows
中运行。Sendkeys
也无法将
SCREEN
按键
{PRTSC}
发送到任何应用程序。
参考资料:MSDN
vb.net中如何执行键盘事件?
执行键盘事件方法如下:
第一步,点击VS工具。
第二步,打开后,新建一个Windows窗体应用程序。
第三步,请看右下方Form的属性栏。
第四步,双击KeyDown。
第五步,输入提示按键代码,如图所示。
第六步,再次输入代码,设置属性KeyPreview为true。
第七步,运行程序,按下举例F5,则会弹出提示,表明已经成功获。
VB制作软键盘
用API keybd_event来模拟按键过程,但是Ctrl+Alt+Del不能模拟,前面已经定义了各个按键的值,需要按什么键替换成对应的值就行了,由于是模拟键盘按键,所以按键发送的对象是当前激活的窗口。
Option Explicit
'
'Virtual Keys, Standard Set
'
Private Const VK_LBUTTON = H1
Private Const VK_RBUTTON = H2
Private Const VK_CANCEL = H3
Private Const VK_MBUTTON = H4 'NOT contiguous with L RBUTTON
Private Const VK_BACK = H8
Private Const VK_TAB = H9
Private Const VK_CLEAR = HC
Private Const VK_RETURN = HD
Private Const VK_SHIFT = H10
Private Const VK_CONTROL = H11
Private Const VK_MENU = H12
Private Const VK_PAUSE = H13
Private Const VK_CAPITAL = H14
Private Const VK_KANA = H15
Private Const VK_HANGEUL = H15 'old name - should be here for compatibility
Private Const VK_HANGUL = H15
Private Const VK_JUNJA = H17
Private Const VK_FINAL = H18
Private Const VK_HANJA = H19
Private Const VK_KANJI = H19
Private Const VK_ESCAPE = H1B
Private Const VK_CONVERT = H1C
Private Const VK_NONCONVERT = H1D
Private Const VK_ACCEPT = H1E
Private Const VK_MODECHANGE = H1F
Private Const VK_SPACE = H20
Private Const VK_PRIOR = H21
Private Const VK_NEXT = H22
Private Const VK_END = H23
Private Const VK_HOME = H24
Private Const VK_LEFT = H25
Private Const VK_UP = H26
Private Const VK_RIGHT = H27
Private Const VK_DOWN = H28
Private Const VK_SELECT = H29
Private Const VK_PRINT = H2A
Private Const VK_EXECUTE = H2B
Private Const VK_SNAPSHOT = H2C
Private Const VK_INSERT = H2D
Private Const VK_DELETE = H2E
Private Const VK_HELP = H2F
'VK_0 thru VK_9 are the same as ASCII '0' thru '9' (=H30 - =H39)
'VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (=H41 - =H5A)
Private Const VK_LWIN = H5B
Private Const VK_RWIN = H5C
Private Const VK_APPS = H5D
Private Const VK_NUMPAD0 = H60
Private Const VK_NUMPAD1 = H61
Private Const VK_NUMPAD2 = H62
Private Const VK_NUMPAD3 = H63
Private Const VK_NUMPAD4 = H64
Private Const VK_NUMPAD5 = H65
Private Const VK_NUMPAD6 = H66
Private Const VK_NUMPAD7 = H67
Private Const VK_NUMPAD8 = H68
Private Const VK_NUMPAD9 = H69
Private Const VK_MULTIPLY = H6A
Private Const VK_ADD = H6B
Private Const VK_SEPARATOR = H6C
Private Const VK_SUBTRACT = H6D
Private Const VK_DECIMAL = H6E
Private Const VK_DIVIDE = H6F
Private Const VK_F1 = H70
Private Const VK_F2 = H71
Private Const VK_F3 = H72
Private Const VK_F4 = H73
Private Const VK_F5 = H74
Private Const VK_F6 = H75
Private Const VK_F7 = H76
Private Const VK_F8 = H77
Private Const VK_F9 = H78
Private Const VK_F10 = H79
Private Const VK_F11 = H7A
Private Const VK_F12 = H7B
Private Const VK_F13 = H7C
Private Const VK_F14 = H7D
Private Const VK_F15 = H7E
Private Const VK_F16 = H7F
Private Const VK_F17 = H80
Private Const VK_F18 = H81
Private Const VK_F19 = H82
Private Const VK_F20 = H83
Private Const VK_F21 = H84
Private Const VK_F22 = H85
Private Const VK_F23 = H86
Private Const VK_F24 = H87
Private Const VK_NUMLOCK = H90
Private Const VK_SCROLL = H91
'
'VK_L* VK_R* - left and right Alt, Ctrl and Shift virtual keys.
'Used only as parameters to GetAsyncKeyState() and GetKeyState().
'No other API or message will distinguish left and right keys in this way.
'
Private Const VK_LSHIFT = HA0
Private Const VK_RSHIFT = HA1
Private Const VK_LCONTROL = HA2
Private Const VK_RCONTROL = HA3
Private Const VK_LMENU = HA4
Private Const VK_RMENU = HA5
'dwFlags
Private Const KEYEVENTF_EXTENDEDKEY = H1
Private Const KEYEVENTF_KEYUP = H2
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command1_Click()
Call keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY, 0) '按下Alt键
Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0) '按下Print Screen键
Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) '抬起Print Screen键
Call keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) '抬起Alt键
Call keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0) '按下Win键
Call keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) '抬起Win键
Call keybd_event(VK_NUMLOCK, 0, KEYEVENTF_EXTENDEDKEY, 0) '按下Num Lock键
Call keybd_event(VK_NUMLOCK, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) '抬起Num Lock键
End Sub
怎样用VB模拟键盘输入
ivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = HC
Private Sub Command1_Click()
Dim hwnd As Long, Thwnd As Long
Shell "notepad.exe", 2 '打开一个记事本,将它最小化
hwnd = FindWindow("Notepad", "无标题 - 记事本") '得到记事本句柄
Thwnd = FindWindowEx(hwnd, 0, "Edit", vbNullString) '得到记事本句柄(就是我们写字的那里)
SendMessage Thwnd, WM_SETTEXT, 0, ByVal "好了,快给我分" '向记事本写入文字
End Sub
网页标题:vb.net虚拟键盘代码,vbs模拟win键
网页网址:http://scgulin.cn/article/hcdisc.html