PDA

View Full Version : فرخوانی برنامه با فشردن یک کلید خاص



dadeBaran
پنج شنبه 08 آبان 1393, 16:07 عصر
سلام
کسی میتونه بگه که چطور میتونم با فشار دادن یک کلید خاص مثله f8 برنامه ام رو اجرا کنم حتی اگه فوکوس رو برنامه نباشه یا مینی مایز و یا تو سیستم تری باشه ...؟


Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer




For i = 1 To 255
results = 0
results = GetAsyncKeyState(i)
If results <> 0 Then
Msgbox(Chr(i))
End If
Next
اینو بلدم ولی این کد برنامه رو خودکار اجراش میکنه . من میخوام وقتی کاربر کلیدی رو فشار داد برنامه اجرا بشه مثله دیکشنری ها ...

Mori Bone
پنج شنبه 08 آبان 1393, 16:19 عصر
http://www.vbforums.com/showthread.php?515051-RESOLVED-VB6-Detect-keypress-outside-your-application&p=3177329&viewfull=1#post3177329

dadeBaran
پنج شنبه 08 آبان 1393, 16:42 عصر
دستتون درد نکنه ...

این کد رو هم میذارم تا کسی دنبالش نچرخه :


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