Re: keyboard event

From: alpine (alpine_don'tsendspam_at_mvps.org)
Date: 09/15/04


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



Relevant Pages

  • Re: Simulating KB input in a Windows app, and reading out results
    ... That depends on the target application. ... probably find it by its control ID. ... If it's not the only edit control ... getting the window which currently has the focus or something like that. ...
    (microsoft.public.win32.programmer.ui)
  • Re: keyboard event
    ... >>i use a tool from PSC i think it's called advanced windows API ... >>destination control. ... >>thanks for the help Bryan ... When doing so, the target doesn't need to have the focus, ...
    (microsoft.public.vb.winapi)
  • Re: keyboard event
    ... >>thanks Bryan ... > edit control residing on the parent window). ... you can walk it to get to the hWnd of the target window. ...
    (microsoft.public.vb.winapi)
  • link popup
    ... I have a link to another page that I would like to popup in another window, ... I know how to change the target of the link to a new ... but how do I control the window size? ...
    (microsoft.public.frontpage.programming)
  • Re: Entwicklung von Unix-Anwendung mit C++ (m/w)/ NRW : Ref.-Nr.: 37302/1
    ... I am responsible for design and implementation of the persistent data server working with mySQL. ... Developed within very short time the product was successfully installed ... Reengineering and implementing a display tool for Experimental Physics Industrial Control System ... Developed an operator interface under X Window for High Energy Physics Accelerator Control System. ...
    (de.markt.arbeit.d)