PDA

View Full Version : حرفه ای: استفاده از کلید های ترکیبی



m.4.r.m
سه شنبه 31 مرداد 1391, 15:06 عصر
یه ماژول پیدا کردم گفتم بزارم همه استفاده کنیم :


Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'Purpose : Test the Keyboard buffer to see which keys have been pressed
'Inputs : vKey1 The character or ascii value of the first key to test
' [vKey2] The character or ascii value of the second key to test
' To call using text use:
' Debug.Pring KeyPressed("S") 'Returns true if the user has the "S" keypressed
' To call using ASCII values use:
' Debug.Pring KeyPressed(vbKeyS) 'Returns true if the user has the "S" keypressed
'Outputs : Returns True if the specified Key/s where pressed
'Examples : To Find out if Control + Q has been pressed use:
' If KeyPressed(vbKeyControl ,vbKeyQ) Then
' or To Find out if Shift + Q has been pressed use:
' If KeyPressed(vbKeyShift ,vbKeyQ) Then
' or To Find out if Alt + Q has been pressed use:
' If KeyPressed(18,vbKeyQ) Then
'Revisions :
Public Function KeyPressed(ByVal vKey1 As Variant, Optional ByVal vKey2 As Variant) As Boolean
Dim bResult As Boolean

'Check First Key (need to call twice, the first call clears
'the keyboard buffer then second checks it's still pressed)
On Error GoTo ErrFailed
If VarType(vKey1) = vbString Then
bResult = CBool(GetAsyncKeyState(Asc(vKey1)))
bResult = CBool(GetAsyncKeyState(Asc(vKey1)))
Else
bResult = CBool(GetAsyncKeyState(vKey1))
bResult = CBool(GetAsyncKeyState(vKey1))
End If

If IsMissing(vKey2) = False Then
'Check Second Key
If VarType(vKey2) = vbString Then
bResult = bResult And CBool(GetAsyncKeyState(Asc(vKey2)))
bResult = bResult And CBool(GetAsyncKeyState(Asc(vKey2)))
Else
bResult = bResult And CBool(GetAsyncKeyState(vKey2))
bResult = bResult And CBool(GetAsyncKeyState(vKey2))
End If
End If
KeyPressed = bResult
Exit Function
ErrFailed:
Debug.Print Err.Description
Debug.Assert False
End Function



نحوه استفاده از این تابع :


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyPressed(vbKeyScrollLock, vbKeyEscape) Then
Form2.Show
End If
End Sub

سپهر-111
سه شنبه 31 مرداد 1391, 15:52 عصر
یه ماژول پیدا کردم گفتم بزارم همه استفاده کنیم :


Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'Purpose : Test the Keyboard buffer to see which keys have been pressed
'Inputs : vKey1 The character or ascii value of the first key to test
' [vKey2] The character or ascii value of the second key to test
' To call using text use:
' Debug.Pring KeyPressed("S") 'Returns true if the user has the "S" keypressed
' To call using ASCII values use:
' Debug.Pring KeyPressed(vbKeyS) 'Returns true if the user has the "S" keypressed
'Outputs : Returns True if the specified Key/s where pressed
'Examples : To Find out if Control + Q has been pressed use:
' If KeyPressed(vbKeyControl ,vbKeyQ) Then
' or To Find out if Shift + Q has been pressed use:
' If KeyPressed(vbKeyShift ,vbKeyQ) Then
' or To Find out if Alt + Q has been pressed use:
' If KeyPressed(18,vbKeyQ) Then
'Revisions :
Public Function KeyPressed(ByVal vKey1 As Variant, Optional ByVal vKey2 As Variant) As Boolean
Dim bResult As Boolean

'Check First Key (need to call twice, the first call clears
'the keyboard buffer then second checks it's still pressed)
On Error GoTo ErrFailed
If VarType(vKey1) = vbString Then
bResult = CBool(GetAsyncKeyState(Asc(vKey1)))
bResult = CBool(GetAsyncKeyState(Asc(vKey1)))
Else
bResult = CBool(GetAsyncKeyState(vKey1))
bResult = CBool(GetAsyncKeyState(vKey1))
End If

If IsMissing(vKey2) = False Then
'Check Second Key
If VarType(vKey2) = vbString Then
bResult = bResult And CBool(GetAsyncKeyState(Asc(vKey2)))
bResult = bResult And CBool(GetAsyncKeyState(Asc(vKey2)))
Else
bResult = bResult And CBool(GetAsyncKeyState(vKey2))
bResult = bResult And CBool(GetAsyncKeyState(vKey2))
End If
End If
KeyPressed = bResult
Exit Function
ErrFailed:
Debug.Print Err.Description
Debug.Assert False
End Function



نحوه استفاده از این تابع :


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyPressed(vbKeyScrollLock, vbKeyEscape) Then
Form2.Show
End If
End Sub



درود برشما
زحمت کشیدی
ولی توضیح میدادی کجاها کاربرد داره دوتا مثال هم بزن . . .
ممنون

Mr'Jamshidy
سه شنبه 31 مرداد 1391, 21:58 عصر
یه ماژول پیدا کردم گفتم بزارم همه استفاده کنیم :


Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'Purpose : Test the Keyboard buffer to see which keys have been pressed
'Inputs : vKey1 The character or ascii value of the first key to test
' [vKey2] The character or ascii value of the second key to test
' To call using text use:
' Debug.Pring KeyPressed("S") 'Returns true if the user has the "S" keypressed
' To call using ASCII values use:
' Debug.Pring KeyPressed(vbKeyS) 'Returns true if the user has the "S" keypressed
'Outputs : Returns True if the specified Key/s where pressed
'Examples : To Find out if Control + Q has been pressed use:
' If KeyPressed(vbKeyControl ,vbKeyQ) Then
' or To Find out if Shift + Q has been pressed use:
' If KeyPressed(vbKeyShift ,vbKeyQ) Then
' or To Find out if Alt + Q has been pressed use:
' If KeyPressed(18,vbKeyQ) Then
'Revisions :
Public Function KeyPressed(ByVal vKey1 As Variant, Optional ByVal vKey2 As Variant) As Boolean
Dim bResult As Boolean

'Check First Key (need to call twice, the first call clears
'the keyboard buffer then second checks it's still pressed)
On Error GoTo ErrFailed
If VarType(vKey1) = vbString Then
bResult = CBool(GetAsyncKeyState(Asc(vKey1)))
bResult = CBool(GetAsyncKeyState(Asc(vKey1)))
Else
bResult = CBool(GetAsyncKeyState(vKey1))
bResult = CBool(GetAsyncKeyState(vKey1))
End If

If IsMissing(vKey2) = False Then
'Check Second Key
If VarType(vKey2) = vbString Then
bResult = bResult And CBool(GetAsyncKeyState(Asc(vKey2)))
bResult = bResult And CBool(GetAsyncKeyState(Asc(vKey2)))
Else
bResult = bResult And CBool(GetAsyncKeyState(vKey2))
bResult = bResult And CBool(GetAsyncKeyState(vKey2))
End If
End If
KeyPressed = bResult
Exit Function
ErrFailed:
Debug.Print Err.Description
Debug.Assert False
End Function



نحوه استفاده از این تابع :


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyPressed(vbKeyScrollLock, vbKeyEscape) Then
Form2.Show
End If
End Sub


آنتی ویروس ها تابع GetAsyncKeyState رو بع عنوان keyLogger میشناسن

m.4.r.m
چهارشنبه 01 شهریور 1391, 09:53 صبح
به نظر من وقتی تو برنامه خودتون بخواین برخی از تنظیمات فقط از طریق کلید های ترکیبی که خودتون تعریف کردین اعمال بشن شاید گزینه خوبی باشه ( البته در حد تئوری ) گفتم ، مثلا از کلید ترکیبی جاهای زیادی می توان استفاده کرد .

Mr'Jamshidy
پنج شنبه 02 شهریور 1391, 08:29 صبح
شاید بهتر باشه برای کلید های ترکیبی کیبرد رو هوک کنی

دیگه نیازی نیست مدام با یک تایمر کلید ها رو چک کنید

اگر هوک کنی خود ویندوز بهت خبر میده که مثلا فلان کلید زده شد

که البته این روش هم مشکلاتی در پی داره

Veteran
پنج شنبه 02 شهریور 1391, 08:44 صبح
شاید بهتر باشه برای کلید های ترکیبی کیبرد رو هوک کنی

دیگه نیازی نیست مدام با یک تایمر کلید ها رو چک کنید

اگر هوک کنی خود ویندوز بهت خبر میده که مثلا فلان کلید زده شد

که البته این روش هم مشکلاتی در پی داره
میشه نمونه بزارید ؟

Mr'Jamshidy
جمعه 03 شهریور 1391, 15:17 عصر
اینم نمونه فقط برنامه رو Stop نکنید!

Mr'Jamshidy
جمعه 03 شهریور 1391, 15:20 عصر
این صفحه رو هم برای کلید ترکیبی ببینید

http://www.codeguru.com/vb/gen/vb_system/keyboard/article.php/c4829/Managing-LowLevel-Keyboard-Hooks-with-the-Windows-API.htm

کد کلید ها

http://msdn.microsoft.com/en-us/library/aa243025%28v=vs.60%29.aspx

Veteran
یک شنبه 05 شهریور 1391, 11:10 صبح
ممنون جناب جمشیدی بابت سورس کد.
سوالی که واسم پیش اموده اینکه برای هوک کردن چه چیزهایی همیشه باید در برنامه حظور داشته باشن.
به عبارت دیگه.... برای هوک کردن به چه چیزهایی نیاز داریم ؟
مثلا ما برای کاربا پنجره های باید هندل رو داشته باشیم.اسم کلاس شی رو داشته باشیم و .....
برای هوک کردن چه چیزهایی نیازه ؟