对于SendKeys这个命令可以send什么,我们可以看下面的列表:

  1. BACKSPACE {BACKSPACE}, {BS}, or {BKSP}  
  2. BREAK {BREAK}  
  3. CAPS LOCK {CAPSLOCK}  
  4. DEL ;or DELETE {DELETE} or {DEL}  
  5. DOWN ARROW {DOWN}  
  6. END {END}  
  7. ENTER {ENTER}or ~  
  8. ESC {ESC}  
  9. HELP {HELP}  
  10. HOME {HOME}  
  11. INS or INSERT {INSERT} or {INS}  
  12. LEFT ARROW {LEFT}  
  13. NUM LOCK {NUMLOCK}  
  14. PAGE DOWN {PGDN}  
  15. PAGE UP {PGUP}  
  16. PRINT SCREEN {PRTSC}  
  17. RIGHT ARROW {RIGHT}  
  18. SCROLL LOCK {SCROLLLOCK}  
  19. TAB {TAB}  
  20. UP ARROW {UP}  
  21. F1 {F1}  
  22. F2 {F2}  
  23. F3 {F3}  
  24. F4 {F4}  
  25. F5 {F5}  
  26. F6 {F6}  
  27. F7 {F7}  
  28. F8 {F8}  
  29. F9 {F9}  
  30. F10 {F10}  
  31. F11 {F11}  
  32. F12 {F12}  
  33. F13 {F13}  
  34. F14 {F14}  
  35. F15 {F15}  
  36. F16 {F16}  
  37.  
  38. SHIFT +  
  39. CTRL ^  
  40. ALT % 

Shell一个应用程序并等待该程序执行完毕后继续运行

Shell & Wait 的程序怎么写? 希望某一 VB 程序利用 Shell 执行某一个外部程序(假设是 notepad.exe)之后, 就一直等到此一程序结束执行时, 才回到 VB 程序继续执行, 该怎么办到呢? 当我们调用 Shell 时, 会传回一个数值, 此一数值称为 Process Id, 利用此 一 Process Id, 我们可以调用 OpenProcess API 取得 Process Handle, 然后 再利用 Process Handle 调用 WaitForSingleObject, 即可等待被 Shell 执行的 程序执行完毕, 才继续向下执行。细节如下: 

1. API 的声明: 

  1. Const SYNCHRONIZE = &H100000  
  2. Const INFINITE = &HFFFFFFFF  
  3. Private Declare Function OpenProcess Lib "kernel32" (ByVal  
  4. dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId  
  5. As Long) As Long  
  6. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As  
  7. Long) As Long  
  8. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal  
  9. hHandle As Long, ByVal dwMilliseconds As Long) As Long 

注:如果以上的声明放在「一般模块」底下, 应将 Declare 之前的 Private 保 留字去掉, 并且在 Const 之前加上 Public 保留字。

2. 程序范例:(以执行 Notepad 程序为例) 

  1. Dim pId As Long, pHnd As Long ’分别声明 Process Id 及 Process Handle 变 数    
  2. pId = Shell("Notepad", vbNormalFocus) ’Shell 传回  
  3. Process Id pHnd = OpenProcess(SYNCHRONIZE, 0, pId) ’ 取得 Process Handle  
  4. If pHnd <> 0 Then Call WaitForSingleObject(pHnd, INFINITE) ’ 无限等待,直到程序结束  
  5. Call CloseHandle(pHnd)  
  6. End If 


相关内容