精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Powerbuilder>>锦上添花 技巧大家谈>>肃清晓通的流毒(1)击键综述

主题:肃清晓通的流毒(1)击键综述
发信人: ilike()
整理人: pblover(1999-10-09 22:40:29), 站内信件
很多人都知道怎样在datawindow按下enter键模拟tab键的效果:
在datawindow中扩展出pbm_dwnprocessenter事件:
加入代码
Send( Handle( This),256,9,Long(0,0))
Return 1

这种方法曾经出现在晓通那一套天价的书上,网上各网站你抄我的,我抄你的,
好象只有这一种方法,一种思路,不知误导了多少人。

今天我就来肃清晓通的流毒。
这种方法其实效果也还可以,只不过是很久以前的Windows 3.1的技术了,在Win
dows95以上的版本,我们有更好,更规范,功能更强的方法来实现。
在windows95以上,特意增加了一个API调用,keybd_event,这个API调用的功能
就是模拟键盘击键。
定义如下:
subroutine keybd_event(uint bVk,uint bScan,long dwFlags,long dwExtraIn
fo ) library 'user32.dll'

// 以下这段抄自MSDN, 是关于各参数的说明
Parameters
bVk 
Specifies a virtual-key code. The code must be a value in the range 1 
to 254. 
bScan 
Specifies a hardware scan code for the key. 
dwFlags 
A set of flag bits that specify various aspects of function operation.
 An application can use any combination of the following predefined co
nstant values to set the flags. Value Meaning 
KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a pr
efix byte having the value 0xE0 (224). 
KEYEVENTF_KEYUP If specified, the key is being released. If not specif
ied, the key is being depressed. 


dwExtraInfo 
Specifies an additional 32-bit value associated with the key stroke. 


谁有耐心慢慢看去,以下只说明我们要用的两个参数
bVk,指需要模拟的击键
dwflags, =0 ,按下  = 2 ,释放

下面我们看看如何实现以下功能:
按下enter键以及下箭头,相当于按下tab键
按下上箭头,相当于按下Shift-tab键
如果是在datawindow下,扩展出pbm_dwnkey,增加如下代码:
If key = KeyEnter! Or Key = KeyDownArrow! Then
keybd_event ( 9, 0, 0 , 0 ) // 按下tab
keybd_event ( 9, 0, 2, 0 ) // 释放tab
Return 1
End If

If Key = KeyUpArrow! Then
keybd_event ( 16, 0, 0, 0 ) // 按下shift
keybd_event ( 9, 0, 0 , 0 ) // 按下tab
keybd_event ( 9, 0, 2, 0 ) // 释放tab
keybd_event ( 16, 0, 2, 0 ) // 释放shift
Return 1
End If

我们也可以在window级实现以上功能,很简单,将上面代码加在window的key事件
中即可.

keybd_event还有一些很神奇的作用,比如以下代码打开windows的“开始菜单”

keybd_event ( 91, 0, 0 , 0 ) // 按下win(不知道应该叫什么)键
keybd_event ( 91, 0, 2, 0 ) // 放开

--
※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.103.137.180]

[关闭][返回]