Visual Basic~~Pressing Key

2008-02-11 6:27 am
1)How to make the program press a key?
Just like if i set a timer,it will press "i".
2)How to ask the program to press enter , ctrl , alt , shift, tab , backspace and other?
i can't use [Asc("Enter")]...

回答 (1)

2008-02-23 6:33 pm
✔ 最佳答案
要用api
準備一個timer1, interval設定成1000
貼上這個:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2


Private Sub Timer1_Timer()
'模擬按下, 74為i字的asc code
keybd_event 74, 0, 0, 0
'模擬放開
keybd_event 74, 0, KEYEVENTF_KEYUP, 0
End Sub

--------------------------
VB範例網
http://www.vbex.net/


收錄日期: 2021-04-20 21:35:12
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080210000051KK03271

檢視 Wayback Machine 備份