|
-
Jun 19th, 2008, 10:35 AM
#1
Thread Starter
New Member
[2005] how do i use "GetAsyncKeyState" API.
hi all,
i am facing problem in using this API "GetAsyncKeyState" can any body please give some coding or some important hints regarding this problem, how could i use it, because i did all possible search but unable to find.
please help me............
regards
-
Jun 19th, 2008, 11:01 AM
#2
Re: [2005] how do i use "GetAsyncKeyState" API.
have a look at my keycodes utility in my signature.
heres the declaration for the api
vb Code:
Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Integer) As Integer
to use it
vb Code:
if GetAsyncKeyState(keycode) then
'key is depressed
end if
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 19th, 2008, 11:30 AM
#3
Thread Starter
New Member
Re: [2005] how do i use "GetAsyncKeyState" API.
In keycode there i will give the code of key as like 32 to 120, but i require that it should give me a keypressed value in generating message.
thanks
-
Jun 19th, 2008, 11:32 AM
#4
Re: [2005] how do i use "GetAsyncKeyState" API.
have a look at the hotkeys link in my signature
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 19th, 2008, 01:20 PM
#5
Thread Starter
New Member
Re: [2005] how do i use "GetAsyncKeyState" API.
my dear, i am agian disturbing you because, problem is not solved , i am going to use "GetAsyncKeyState" API to generate a messagebox to show keypressed value, when i press any key from keyboard.
-
Jun 19th, 2008, 01:27 PM
#6
Re: [2005] how do i use "GetAsyncKeyState" API.
GetAsyncKeyState doesn't notify you when a key is pressed. you call GetAsyncKeyState to check if a key is being held down.
try this
vb Code:
Public Class Form1
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
MsgBox(e.KeyChar)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 19th, 2008, 01:33 PM
#7
Re: [2005] how do i use "GetAsyncKeyState" API.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 19th, 2008, 01:41 PM
#8
Thread Starter
New Member
Re: [2005] how do i use "GetAsyncKeyState" API.
thanks for taking some time to answer my question but, the coding that i am sending you it belongs to vb 6.0, it is all functioning well and giving accurate result as i require,but i am unable to convert it in vb.NET 2005
if you have some time then i will request you how to convert this code in vb.NET 2005
Code:
//In module
Public Const DT_CENTER = &H1
Public Const DT_WORDBREAK = &H10
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Global Cnt As Long, sSave As String, sOld As String, Ret As String
Dim Tel As Long
Function GetPressedKey() As String
For Cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Ret = GetPressedKey
If Ret <> sOld Then
sOld = Ret
sSave = sSave + sOld
End If
End Sub
//In Form1
Private Sub Form_Load()
Me.Caption = "action form"
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Paint()
Dim R As RECT
Const mStr = "Start from here."
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Draw the text on the form
DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
'Show all the typed keys
MsgBox sSave
End Sub
-
Jun 19th, 2008, 01:47 PM
#9
Re: [2005] how do i use "GetAsyncKeyState" API.
thats a keylogger. its against the policy of this forum to assist with malicious software
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 19th, 2008, 01:49 PM
#10
Thread Starter
New Member
Re: [2005] how do i use "GetAsyncKeyState" API.
my post #8 contains "GetAsyncKeyState" API, so how to use it in vb.NET
best wished for you in completion of my work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|