Страница: 1 |
|
Вопрос: SetTimer + GetAsyncKeyState + VBA Excel
|
Добавлено: 04.09.09 10:18
|
|
Автор вопроса: AngryBadger
|
Уважаемые, как сделать чтобы это сцу#о отлавливало нажатия кнопок в Do-Loop'е все ОК, все ловит, а с таймером не хочет почему-то, а при использовании [/source]If GetAsyncKeyState(VK_LEFT) Then
Debug.Print "Left" [/source] при одном нажатии печатает несколько раз. Вообщем как их соединить, чтобы при разовом нажатии отлавливалось одно нажатие? Я вот думал как-нибудь hook использовать, но рук и мозга пока нехватает.
Собственно код, который не работает:
[source]
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Function Getasynckeystate Lib "user32" Alias "GetAsyncKeyState" (ByVal VKEY As Long) As Integer
Public elpTm As Long
Public tmrID As Long
Const VK_LEFT As Long = &H25
Const VK_RIGHT As Long = &H27
Const VK_DOWN As Long = &H28
Const VK_UP As Long = &H26
Const VK_SPACE As Long = &H20
Sub main()
tmrID = SetTimer(&H0, &H0, 1, AddressOf tmrPrc)
End Sub
Sub tmrKill()
KillTimer &H0, tmrID
End Sub
Public Sub tmrPrc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTimer As Long)
elpTm = elpTm + 1
keystate = Getasynckeystate(37)
If (keystate And &H1) = &H1 Then Debug.Print "Left"
keystate = Getasynckeystate(39)
If (keystate And &H1) = &H1 Then Debug.Print "Right"
keystate = Getasynckeystate(38)
If (keystate And &H1) = &H1 Then Debug.Print "Down"
keystate = Getasynckeystate(40)
If (keystate And &H1) = &H1 Then Debug.Print "Up"
keystate = Getasynckeystate(32)
If (keystate And &H1) = &H1 Then Debug.Print "Space"
If elpTm = 1000 Then
tmrKill
elpTm = 0
End If
End Sub
[/source]
Ответить
|
Номер ответа: 1 Автор ответа: AngryBadger
Вопросов: 33 Ответов: 245
|
Профиль | | #1
|
Добавлено: 04.09.09 10:20
|
- Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
- Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
- Public Declare Function Getasynckeystate Lib "user32" Alias "GetAsyncKeyState" (ByVal VKEY As Long) As Integer
- Public elpTm As Long
- Public tmrID As Long
- Const VK_LEFT As Long = &H25
- Const VK_RIGHT As Long = &H27
- Const VK_DOWN As Long = &H28
- Const VK_UP As Long = &H26
- Const VK_SPACE As Long = &H20
-
- Sub main()
- tmrID = SetTimer(&H0, &H0, 1, AddressOf tmrPrc)
- End Sub
-
- Sub tmrKill()
- KillTimer &H0, tmrID
- End Sub
-
-
- Public Sub tmrPrc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTimer As Long)
- elpTm = elpTm + 1
-
- keystate = Getasynckeystate(37)
- If (keystate And &H1) = &H1 Then Debug.Print "Left"
- keystate = Getasynckeystate(39)
- If (keystate And &H1) = &H1 Then Debug.Print "Right"
- keystate = Getasynckeystate(38)
- If (keystate And &H1) = &H1 Then Debug.Print "Down"
- keystate = Getasynckeystate(40)
- If (keystate And &H1) = &H1 Then Debug.Print "Up"
- keystate = Getasynckeystate(32)
- If (keystate And &H1) = &H1 Then Debug.Print "Space"
-
- If elpTm = 1000 Then
- tmrKill
- elpTm = 0
- End If
-
- End Sub
Ответить
|
Страница: 1 |
Поиск по форуму