• 按键公众号 :
按键精灵电脑版
立即下载

软件版本:2014.06
软件大小:22.9M
更新时间:2021-12-03

按键精灵安卓版
立即下载

软件版本:3.7.2
软件大小:46.2M
更新时间:2023-05-10

按键精灵iOS版
立即下载

软件版本:1.8.0
软件大小:29.2M
更新时间:2023-03-21

按键手机助手
立即下载

软件版本:3.8.0
软件大小:262M
更新时间:2023-05-30

快捷导航

登录 后使用快捷导航
没有帐号? 注册

发新话题 回复该主题

[VB代码]postmessage向记事本发送字符 [复制链接]

1#
postmessage向记事本发送字符
  1. Option Explicit
  2. 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
  3. Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
  4. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  5. 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
  6. Private Const WM_KEYDOWN = &H100
  7. Private Const WM_KEYUP = &H101
  8. Private Const WM_CHAR = &H102
  9. Function MakeKeyLparam(ByVal VirtualKey As Long, ByVal flag As Long) As Long
  10. Dim s As String
  11. Dim Firstbyte As String 'lparam参数的24-31位
  12. If flag = WM_KEYDOWN Then '如果是按下键
  13. Firstbyte = "00"
  14. Else
  15. Firstbyte = "C0" '如果是释放键
  16. End If
  17. Dim Scancode As Long
  18. '获得键的扫描码
  19. Scancode = MapVirtualKey(VirtualKey, 0)
  20. Dim Secondbyte As String 'lparam参数的16-23位,即虚拟键扫描码
  21. Secondbyte = Right("00" & Hex(Scancode), 2)
  22. s = Firstbyte & Secondbyte & "0001" '0001为lparam参数的0-15位,即发送次数和其它扩展信息
  23. MakeKeyLparam = Val("&H" & s)
  24. End Function
  25. Private Sub Form_Load()
  26. Shell "notepad.exe", vbNormalFocus
  27. Dim NotepadHwnd As Long, hwnd As Long
  28. NotepadHwnd = FindWindow("notepad", vbNullString)
  29. '得到窗口类名为Edit的窗口句柄
  30. hwnd = FindWindowEx(NotepadHwnd, 0, "Edit", vbNullString)
  31. PostMessage hwnd, WM_KEYDOWN, vbKeyA, MakeKeyLparam(vbKeyA, WM_KEYDOWN) '按下A键
  32. PostMessage hwnd, WM_CHAR, vbKeyS, MakeKeyLparam(vbKeyS, WM_KEYDOWN) '输入字符A
  33. PostMessage hwnd, WM_KEYUP, vbKeyY, MakeKeyLparam(vbKeyY, WM_KEYUP) '释放A键
复制代码

发新话题 回复该主题