?
Solved

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

Posted on 2003-03-08
7
Medium Priority
?
156 Views
Last Modified: 2010-05-01
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
Comment
Question by:S-L-D-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 

Author Comment

by:S-L-D-
ID: 8094834
Thanks
0
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 8095285
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
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 8095296
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
Independent Software Vendors: 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!

 

Author Comment

by:S-L-D-
ID: 8095381
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
 

Author Comment

by:S-L-D-
ID: 8095448
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
 
LVL 2

Accepted Solution

by:
spauljoseph earned 80 total points
ID: 8096588
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
 

Author Comment

by:S-L-D-
ID: 8097372
:)
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question