Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Вопрос по горячим клавишам Добавлено: 02.04.03 09:30  

Автор вопроса:  Vit | Web-сайт: www.home-soft.jino-net.ru

Я знаю про функцию, перехватывающую внешние нажания клавиатуры (нажатия даже, если окно программы неактивно). Кто может сказать какая функция позволяет назначать определённые действия на сочетания клавиш (это другая функция).

Ответить

  Ответы Всего ответов: 1  

Номер ответа: 1
Автор ответа:
 E-Man



Вопросов: 3
Ответов: 132
 Профиль | | #1 Добавлено: 02.04.03 12:39

А какая? Надеюсь не GetAsyncKeyState?

Вот нормальные ХотКеи, которых сама Винда не гнушается:

Private Const MOD_ALT = &H1

Private Const MOD_CONTROL = &H2

Private Const MOD_SHIFT = &H4

Private Const PM_REMOVE = &H1

Private Const WM_HOTKEY = &H312

Private Type POINTAPI

x As Long

y As Long

End Type

Private Type Msg

hWnd As Long

Message As Long

wParam As Long

lParam As Long

time As Long

pt As POINTAPI

End Type

Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long

Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long

Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long

Private Declare Function WaitMessage Lib "user32" () As Long

Private bCancel As Boolean

Private Sub ProcessMessages()

Dim Message As Msg

'loop until bCancel is set to True

Do While Not bCancel

'wait for a message

WaitMessage

'check if it's a HOTKEY-message

If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then

'minimize the form

WindowState = vbMinimized

End If

'let the operating system process other events

DoEvents

Loop

End Sub

Private Sub Form_Load()

Dim ret As Long

bCancel = False

'register the Ctrl-F hotkey

ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)

'show some information

Me.AutoRedraw = True

Me.Print "Press CTRL-F to minimize this form"

'show the form and

Show

'process the Hotkey messages

ProcessMessages

End Sub

Private Sub Form_Unload(Cancel As Integer)

bCancel = True

'unregister hotkey

Call UnregisterHotKey(Me.hWnd, &HBFFF&)

End Sub

И еще одно: какие действия? клавиатурные?

(к примеру)

Const VK_H = 72

Const VK_E = 69

Const VK_L = 76

Const VK_O = 79

Const KEYEVENTF_EXTENDEDKEY = &H1

Const KEYEVENTF_KEYUP = &H2

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 Form_KeyPress(KeyAscii As Integer)

'Print the key on the form

Me.Print Chr$(KeyAscii);

End Sub

Private Sub Form_Paint()

Me.Cls

keybd_event VK_H, 0, 0, 0 ' press H

keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0 ' release H

keybd_event VK_E, 0, 0, 0 ' press E

keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0 ' release E

keybd_event VK_L, 0, 0, 0 ' press L

keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L

keybd_event VK_L, 0, 0, 0 ' press L

keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L

keybd_event VK_O, 0, 0, 0 ' press O

keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0 ' release O

End Sub

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам