Re: keyboard event
From: alpine (alpine_don'tsendspam_at_mvps.org)
Date: 09/15/04
- Next message: RicardoFurtado: "How to Protect the software Directory"
- Previous message: alpine: "Re: Activate application running in system tray"
- In reply to: David Saint: "Re: keyboard event"
- Next in thread: David Saint: "Re: keyboard event"
- Reply: David Saint: "Re: keyboard event"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 15 Sep 2004 08:35:42 -0600
On Wed, 15 Sep 2004 09:05:12 +0100, "David Saint" <beer@hotmail.com>
wrote:
>
>"alpine" <alpine_don'tsendspam@mvps.org> wrote in message
>news:0hjek0p0jmie47v4om4j7i22r4odnt26i5@4ax.com...
>> On Tue, 14 Sep 2004 18:37:40 +0100, "David Saint" <beer@hotmail.com>
>> wrote:
>>
>> >
>> >"alpine" <alpine_don'tsendspam@mvps.org> wrote in message
>> >news:ji0ek058lmv0k1j9q5jpkhvh75ahnt64al@4ax.com...
>> >> On Tue, 14 Sep 2004 08:53:22 +0100, "David Saint" <beer@hotmail.com>
>> >> wrote:
>> >>
>> >> >hello everyone
>> >> >
>> >> >i have had to re-post this question due to a lack
>> >> >of any responce from another group.
>> >> >
>> >> >i really need some help with this.
>> >> >this is what i am currently using in my vb6 app.
>> >> >
>> >> >keybd_event VK_T, 0, 0, 0
>> >> >keybd_event VK_T, 0, KEYEVENTF_KEYUP, 0
>> >> >
>> >> >the problem is this, the user is able to unknowingly
>> >> >create an error by giving the focus to another window.
>> >> >
>> >> >can i use something else (more reliable) to send keys to another
>window
>> >> >without an error being caused if my app loses focus ? i have already
>> >> >tried the SetFocusAPI in a loop, but that is still not 100% effective.
>> >> >
>> >> >could SendMessage, SetWindowText or something like that be what
>> >> >i need to use for a 100% garanteed result ?
>> >> >
>> >> >thanks
>> >>
>> >>
>> >> The methods you use will depend quite a bit on the target you want to
>> >> send text into. If it is a standard edit control, you will probably
>> >> be better off using SetWindowText or sending a WM_SETTEXT message. Of
>> >> course, you will need the hWnd of the target window in order to use
>> >> either of these but getting that usually isn't too much of a problem
>> >> using some combination of the FindWindow, FindWindowEx and/or
>> >> EnumChildWindows API functions.
>> >>
>> >> HTH,
>> >> Bryan
>> >> ____________________________________________________________
>> >> New Vision Software "When the going gets weird,"
>> >> Bryan Stafford "the weird turn pro."
>> >> alpine_don'tsendspam@mvps.org Hunter S. Thompson -
>> >> Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
>> >
>> >Bryan
>> >i'm aready able to find the window's hWnd through
>> >
>> >Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA"
>> >(ByVal lpClassName As _
>> >Any, ByVal lpWindowName As Any) As Long
>> >...
>> >dwnd = FindWindow(vbNullString, "WindowName")
>> >...
>> >i didn't realise this was going to be the tricky part.
>> >
>> >thanks Bryan
>>
>>
>> Use the Spy++ application that comes with VS to find the class name of
>> the actual target control (from your description I assume it is an
>> edit control residing on the parent window). Once you know the window
>> hierarchy, you can walk it to get to the hWnd of the target window.
>>
>> HTH,
>> Bryan
>> ____________________________________________________________
>> New Vision Software "When the going gets weird,"
>> Bryan Stafford "the weird turn pro."
>> alpine_don'tsendspam@mvps.org Hunter S. Thompson -
>> Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
>
>ok thanks Bryan
>i use a tool from PSC i think it's called advanced windows API
>it acts like visual studio's spy tool but you can do even more with this one
>plus, all the code for it is freely available.
>
>how could i maintain the focus on the window control
>once i found it ? at the moment in testing, if i click anywhere
>while the operation is running the keys are not sent to the correct
>destination control.
>
>what about something like this
>
>hWnd = FindWindow(vbNullString, sWinTxt)
>If hWnd = 0 Then
>Exit Sub
>Else
>For x = 1 To 5000
> r = SetFocusAPI(hWnd)
>...
>' SetWindowText or WM_SETTEXT code here
>...
>Next
>End If
>
>this does work in a fashion, but it seems stall until the loop is complete
>then it deals with text ?
>
>thanks for the help Bryan
You should use WM_SETTEXT since you are sending your text to another
process. When doing so, the target doesn't need to have the focus,
you just set the entire string you wish to place into the target in a
single call.
Public Const WM_SETTEXT As Long = &HC&
Public Declare Function SendMessageByString Lib "user32" Alias
"SendMessageA" (ByVal hWnd&, ByVal wMsg&, ByVal wParam&, ByVal
lParam$) As Long
Call SendMessageByString(hTarget, WM_SETTEXT, 0&, "This is a test!")
Where hTarget is the handle of the target control.
HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
- Next message: RicardoFurtado: "How to Protect the software Directory"
- Previous message: alpine: "Re: Activate application running in system tray"
- In reply to: David Saint: "Re: keyboard event"
- Next in thread: David Saint: "Re: keyboard event"
- Reply: David Saint: "Re: keyboard event"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|