Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Send a keystroke to a hwnd window
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00889676
Message ID:
00889780
Views:
26
I played with keyb_event for a while and everytime I used it, all of my keys started producing unexpected results until I reboot. For instance, after this:

ReturnValue = PostMessage(hwnd, WM_KEYDOWN, wParam, 0)
ReturnValue = Keybd_Event(97,0,0,0)
ReturnValue = Keybd_Event(97,0,2,0)

No matter what I sent as the first parameter, whenever I returned after testing it, click and dblclick and pressing ENTER has strange results. If I double-click on any icon, it brings up its properties, etc. Very strange so I am leaving that one alone for awhile.

Anyway, the below is the ONLY thing that works so far and it works well. The only problem is that I am not supposed to use the windows script at all and I need to stick with pure API so I will have to find something else. I will post it though for lurkers since it works so well. Someone else may need it one day.
*--App has already been launched using CREATEPROCESS and now it is in 
*--a loop using GETEXITCODEPROCESS() waiting for it to close but the
*--password box pops up first and a password must be entered without 
*--the user's input at all behind the scenes so the app will run.
*--So far this has always worked the first time
IF lnclosepass < 3 .and. PassWin('Password')
   = Sleep (3000)
   lnclosepass = lnclosepass + 1
ENDIF

FUNCTION PassWin
PARAMETER tcTitle

DECLARE INTEGER FindWindow IN Win32API AS FindWindow STRING, STRING
lnwindow = FindWindow(0,tcTitle)

IF lnwindow > 0

   #DEFINE WM_SETFOCUS 0x0007	
   DECLARE SHORT PostMessage IN user32; 
     INTEGER   hWnd,; 
     INTEGER   Msg,; 
     STRING    wParam,; 
     INTEGER   lParam 
    
   hwnd = lnwindow
   ReturnValue = PostMessage(hwnd, WM_SETFOCUS, 0, 0)
   oShell = Createobject("wscript.shell")
   oShell.Sendkeys("{~}")
   oshell.Sendkeys("P")
   oShell.sendkeys("a")
   oShell.sendkeys("w")
   oShell.sendkeys("w")
   oShell.sendkeys("w")
   oShell.sendkeys("o")
   oShell.sendkeys("r")
   oShell.sendkeys("d")
   oShell.sendkeys("{ENTER}")
   RELEASE oshell
   RETURN .T.

ELSE
   RETURN .F.
ENDIF
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform