Имитация нажатия клавиши

Программирование на Visual Basic, главный форум. Обсуждение тем программирования на VB 1—6.
Даже если вы плохо разбираетесь в VB и программировании вообще — тут вам помогут. В разумных пределах, конечно.
Правила форума
Темы, в которых будет сначала написано «что нужно сделать», а затем просьба «помогите», будут закрыты.
Читайте требования к создаваемым темам.
Helix
Начинающий
Начинающий
 
Сообщения: 6
Зарегистрирован: 10.03.2004 (Ср) 19:28

Имитация нажатия клавиши

Сообщение Helix » 27.03.2004 (Сб) 23:47

Здравствуйте!
Подскажите, пожалуйста, как через нажатие кнопки на форме сымитировать нажатие клавиши на клавиатуре. Заранее благодарен.

A.A.Z.
Член-корреспондент академии VBStreets
Член-корреспондент академии VBStreets
 
Сообщения: 3035
Зарегистрирован: 30.06.2003 (Пн) 13:38

Сообщение A.A.Z. » 28.03.2004 (Вс) 0:00

На форме кнопка.

Код: Выделить всё
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub Command1_Click()
Dim S$, I&
S = InputBox("Какую клавишу ""нажать""?", , "A")
If S = "" Then Exit Sub
For I = 1 To Len(S)
keybd_event Asc(Mid$(S, I, 1)), 0, 0, 0
keybd_event Asc(Mid$(S, I, 1)), 0, 2, 0
Next
MsgBox "Готово!"
End Sub

Private Sub Form_Load()
Command1.Caption = "Нажми меня!!!"
End Sub
Нет меня больше

Helix
Начинающий
Начинающий
 
Сообщения: 6
Зарегистрирован: 10.03.2004 (Ср) 19:28

Сообщение Helix » 28.03.2004 (Вс) 13:08

A.A.Z. писал(а):На форме кнопка.

Код: Выделить всё
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub Command1_Click()
Dim S$, I&
S = InputBox("Какую клавишу ""нажать""?", , "A")
If S = "" Then Exit Sub
For I = 1 To Len(S)
keybd_event Asc(Mid$(S, I, 1)), 0, 0, 0
keybd_event Asc(Mid$(S, I, 1)), 0, 2, 0
Next
MsgBox "Готово!"
End Sub

Private Sub Form_Load()
Command1.Caption = "Нажми меня!!!"
End Sub


Благодарю за ответ. Но вот такая проблемма: как сымитировать нажатие клавиши F1?

A.A.Z.
Член-корреспондент академии VBStreets
Член-корреспондент академии VBStreets
 
Сообщения: 3035
Зарегистрирован: 30.06.2003 (Пн) 13:38

Сообщение A.A.Z. » 28.03.2004 (Вс) 15:08

Это должно помочь:
Код: Выделить всё
Private Const VK_ACCEPT As Long = &H1E
Private Const VK_ADD As Long = &H6B
Private Const VK_APPS As Long = &H5D
Private Const VK_ATTN As Long = &HF6
Private Const VK_BACK As Long = &H8
Private Const VK_BROWSER_BACK As Long = &HA6
Private Const VK_BROWSER_FAVORITES As Long = &HAB
Private Const VK_BROWSER_FORWARD As Long = &HA7
Private Const VK_BROWSER_HOME As Long = &HAC
Private Const VK_BROWSER_REFRESH As Long = &HA8
Private Const VK_BROWSER_SEARCH As Long = &HAA
Private Const VK_BROWSER_STOP As Long = &HA9
Private Const VK_CANCEL As Long = &H3
Private Const VK_CAPITAL As Long = &H14
Private Const VK_CLEAR As Long = &HC
Private Const VK_CONTROL As Long = &H11
Private Const VK_CONVERT As Long = &H1C
Private Const VK_CRSEL As Long = &HF7
Private Const VK_DBE_ALPHANUMERIC As Long = &Hf0
Private Const VK_DBE_CODEINPUT As Long = &Hfa
Private Const VK_DBE_DBCSCHAR As Long = &Hf4
Private Const VK_DBE_DETERMINESTRING As Long = &Hfc
Private Const VK_DBE_ENTERDLGCONVERSIONMODE As Long = &Hfd
Private Const VK_DBE_ENTERIMECONFIGMODE As Long = &Hf8
Private Const VK_DBE_ENTERWORDREGISTERMODE As Long = &Hf7
Private Const VK_DBE_FLUSHSTRING As Long = &Hf9
Private Const VK_DBE_HIRAGANA As Long = &Hf2
Private Const VK_DBE_KATAKANA As Long = &Hf1
Private Const VK_DBE_NOCODEINPUT As Long = &Hfb
Private Const VK_DBE_NOROMAN As Long = &Hf6
Private Const VK_DBE_ROMAN As Long = &Hf5
Private Const VK_DBE_SBCSCHAR As Long = &Hf3
Private Const VK_DECIMAL As Long = &H6E
Private Const VK_DELETE As Long = &H2E
Private Const VK_DIVIDE As Long = &H6F
Private Const VK_DOWN As Long = &H28
Private Const VK_END As Long = &H23
Private Const VK_EREOF As Long = &HF9
Private Const VK_ESCAPE As Long = &H1B
Private Const VK_EXECUTE As Long = &H2B
Private Const VK_EXSEL As Long = &HF8
Private Const VK_F1 As Long = &H70
Private Const VK_F10 As Long = &H79
Private Const VK_F11 As Long = &H7A
Private Const VK_F12 As Long = &H7B
Private Const VK_F13 As Long = &H7C
Private Const VK_F14 As Long = &H7D
Private Const VK_F15 As Long = &H7E
Private Const VK_F16 As Long = &H7F
Private Const VK_F17 As Long = &H80
Private Const VK_F18 As Long = &H81
Private Const VK_F19 As Long = &H82
Private Const VK_F2 As Long = &H71
Private Const VK_F20 As Long = &H83
Private Const VK_F21 As Long = &H84
Private Const VK_F22 As Long = &H85
Private Const VK_F23 As Long = &H86
Private Const VK_F24 As Long = &H87
Private Const VK_F3 As Long = &H72
Private Const VK_F4 As Long = &H73
Private Const VK_F5 As Long = &H74
Private Const VK_F6 As Long = &H75
Private Const VK_F7 As Long = &H76
Private Const VK_F8 As Long = &H77
Private Const VK_F9 As Long = &H78
Private Const VK_FINAL As Long = &H18
Private Const VK_HANGEUL As Long = &H15
Private Const VK_HANGUL As Long = &H15
Private Const VK_HANJA As Long = &H19
Private Const VK_HELP As Long = &H2F
Private Const VK_HOME As Long = &H24
Private Const VK_ICO_00 As Long = &HE4
Private Const VK_ICO_CLEAR As Long = &HE6
Private Const VK_ICO_HELP As Long = &HE3
Private Const VK_INSERT As Long = &H2D
Private Const VK_JUNJA As Long = &H17
Private Const VK_KANA As Long = &H15
Private Const VK_KANJI As Long = &H19
Private Const VK_LAUNCH_APP1 As Long = &HB6
Private Const VK_LAUNCH_APP2 As Long = &HB7
Private Const VK_LAUNCH_MAIL As Long = &HB4
Private Const VK_LAUNCH_MEDIA_SELECT As Long = &HB5
Private Const VK_LBUTTON As Long = &H1
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_LEFT As Long = &H25
Private Const VK_LMENU As Long = &HA4
Private Const VK_LSHIFT As Long = &HA0
Private Const VK_LWIN As Long = &H5B
Private Const VK_MBUTTON As Long = &H4
Private Const VK_MEDIA_NEXT_TRACK As Long = &HB0
Private Const VK_MEDIA_PLAY_PAUSE As Long = &HB3
Private Const VK_MEDIA_PREV_TRACK As Long = &HB1
Private Const VK_MEDIA_STOP As Long = &HB2
Private Const VK_MENU As Long = &H12
Private Const VK_MODECHANGE As Long = &H1F
Private Const VK_MULTIPLY As Long = &H6A
Private Const VK_NEXT As Long = &H22
Private Const VK_NONAME As Long = &HFC
Private Const VK_NONCONVERT As Long = &H1D
Private Const VK_NUMLOCK As Long = &H90
Private Const VK_NUMPAD0 As Long = &H60
Private Const VK_NUMPAD1 As Long = &H61
Private Const VK_NUMPAD2 As Long = &H62
Private Const VK_NUMPAD3 As Long = &H63
Private Const VK_NUMPAD4 As Long = &H64
Private Const VK_NUMPAD5 As Long = &H65
Private Const VK_NUMPAD6 As Long = &H66
Private Const VK_NUMPAD7 As Long = &H67
Private Const VK_NUMPAD8 As Long = &H68
Private Const VK_NUMPAD9 As Long = &H69
Private Const VK_OEM_1 As Long = &HBA
Private Const VK_OEM_102 As Long = &HE2
Private Const VK_OEM_2 As Long = &HBF
Private Const VK_OEM_3 As Long = &HC0
Private Const VK_OEM_4 As Long = &HDB
Private Const VK_OEM_5 As Long = &HDC
Private Const VK_OEM_6 As Long = &HDD
Private Const VK_OEM_7 As Long = &HDE
Private Const VK_OEM_8 As Long = &HDF
Private Const VK_OEM_ATTN As Long = &HF0
Private Const VK_OEM_AUTO As Long = &HF3
Private Const VK_OEM_AX As Long = &HE1
Private Const VK_OEM_BACKTAB As Long = &HF5
Private Const VK_OEM_CLEAR As Long = &HFE
Private Const VK_OEM_COMMA As Long = &HBC
Private Const VK_OEM_COPY As Long = &HF2
Private Const VK_OEM_CUSEL As Long = &HEF
Private Const VK_OEM_ENLW As Long = &HF4
Private Const VK_OEM_FINISH As Long = &HF1
Private Const VK_OEM_FJ_JISHO As Long = &H92
Private Const VK_OEM_FJ_LOYA As Long = &H95
Private Const VK_OEM_FJ_MASSHOU As Long = &H93
Private Const VK_OEM_FJ_ROYA As Long = &H96
Private Const VK_OEM_FJ_TOUROKU As Long = &H94
Private Const VK_OEM_JUMP As Long = &HEA
Private Const VK_OEM_MINUS As Long = &HBD
Private Const VK_OEM_NEC_EQUAL As Long = &H92
Private Const VK_OEM_PA1 As Long = &HEB
Private Const VK_OEM_PA2 As Long = &HEC
Private Const VK_OEM_PA3 As Long = &HED
Private Const VK_OEM_PERIOD As Long = &HBE
Private Const VK_OEM_PLUS As Long = &HBB
Private Const VK_OEM_RESET As Long = &HE9
Private Const VK_OEM_WSCTRL As Long = &HEE
Private Const VK_PA1 As Long = &HFD
Private Const VK_PACKET As Long = &HE7
Private Const VK_PAUSE As Long = &H13
Private Const VK_PLAY As Long = &HFA
Private Const VK_PRINT As Long = &H2A
Private Const VK_PRIOR As Long = &H21
Private Const VK_PROCESSKEY As Long = &HE5
Private Const VK_RBUTTON As Long = &H2
Private Const VK_RCONTROL As Long = &HA3
Private Const VK_RETURN As Long = &HD
Private Const VK_RIGHT As Long = &H27
Private Const VK_RMENU As Long = &HA5
Private Const VK_RSHIFT As Long = &HA1
Private Const VK_RWIN As Long = &H5C
Private Const VK_SCROLL As Long = &H91
Private Const VK_SELECT As Long = &H29
Private Const VK_SEPARATOR As Long = &H6C
Private Const VK_SHIFT As Long = &H10
Private Const VK_SLEEP As Long = &H5F
Private Const VK_SNAPSHOT As Long = &H2C
Private Const VK_SPACE As Long = &H20
Private Const VK_SUBTRACT As Long = &H6D
Private Const VK_TAB As Long = &H9
Private Const VK_UP As Long = &H26
Private Const VK_VOLUME_DOWN As Long = &HAE
Private Const VK_VOLUME_MUTE As Long = &HAD
Private Const VK_VOLUME_UP As Long = &HAF
Private Const VK_XBUTTON1 As Long = &H5
Private Const VK_XBUTTON2 As Long = &H6
Private Const VK_ZOOM As Long = &HFB

Вставляешь константу на место Asc(Mid$(S, I, 1)), т.е.
Код: Выделить всё
keybd_event VK_F1, 0, 0, 0
keybd_event VK_F1, 0, 2, 0
Нет меня больше


Вернуться в Visual Basic 1–6

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 81

    TopList