Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Anyone know how to identify a key pressed if my Form isnt Activated???

I think it I want will bo not hard for You :)

Well... i Need a Code or a API that identify a key pressed (for example in MS WORD). I would like that key be showed in my (textbox , for example). Can anyone help me please??? Ill be so much thanks :o)

Cya all

*** Sorry for the bad english.
0
S-L-D-
Asked:
S-L-D-
  • 4
  • 2
1 Solution
 
S-L-D-Author Commented:
Thanks
0
 
PlanetCppCommented:
you have to hook another program to get keypresses
if its another thread then the hook provedure must be in a DLL file, so you have to know how to create a DLL
basically all you do is use
SetWindowsHookEx with type WH_KEYBOARD type (you cant alter the keys this way, to alter keys you set a WH_GETMESSAGE hook and change the calues of the keys from wm_char)
first you need to get the process id of the application, you get the hwnd which im asuming you know how to do. FindWindow and FindWindwEx if you dont know..
use
GetWindowThreadProcessID(handle,processID)
process id is passed byref and in vb id say its a long value, its a DWORD in c++
then you use that for the thread id
in the dll you would make a StartHook function to star it
in that function
SetWindowsHookEx(WH_KEYBOARD,addressof MyKeyBoardProc,dllinstance,processID)
you ge tthe dllinstance when the dll loads, you know or you'll see when you learn how to make one :o\
then also in the dll you have to have a keyboard proc
in c++ it's
LRESULT CALLBACK MyKeyBoardProc(int code,WPARAM wParam,LPARAM lParam);
so in VB i would write
function MyKeyBoardProc(code as integer,wParam as long,lparam as long) as long
thats where the data is passed, all keyboard info will go through that function before it goes to the window you hooked.
0
 
PlanetCppCommented:
i forgot you have to also unhook the window with UnhookWindowsHookEx(long value you got from setwindowshook)
hook = SetwindowsHookEx(.....)
then later on
UnhookWindowsHookEx(hook);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
S-L-D-Author Commented:
im so thanks PlanetCpp, but im a newbie yet, i dont know how to do it and i dont know this forum yes... im a little lost in all of that.

Maybe anyone can get some code here??? plz... ill be so thanks
0
 
S-L-D-Author Commented:
im so thanks PlanetCpp, but im a newbie yet, i dont know how to do it and i dont know this forum yes... im a little lost in all of that.

Maybe anyone can get some code here??? plz... ill be so thanks
0
 
spauljosephCommented:
Just use this.

'Place this in Global Declaration
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Dim KeyLoop As Byte
Dim FoundKeys As String
Dim KeyResult As Long

Private Sub tmrKeys_Timer()
    On Error Resume Next
    For KeyLoop = 1 To 255
        KeyResult = GetAsyncKeyState(KeyLoop)
        If KeyResult = -32767 Then
            txtKeys.Text = txtKeys.Text & Chr(KeyLoop)
        End If
    Next
End Sub

'Note txtKeys is a TextBox and tmrKeys is a Timer set interval to 20 for faster access.
0
 
S-L-D-Author Commented:
:)
im so happy now!!! All you in this forum is really cool :)

ill continue trying to know more about vb and about this forum... so much thx for now... and the next time I ll try to know how functions have this "points" in this forum :)

especial thx to who helped me at my first time here

byebye
Cu later
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now