Newsgroup: it.comp.lang.visual-basic
Titolo: sendkeys che fa le bizze?

vi è mai successo?
invio dei tasti con sendkeys ad una finestrella (non mia)...
certi tasti vanno, altri no ma se li "pigio" a mano, vanno tutti.
ad esempio    SendKeys "%d", False (o SendKeys "%d", True): non va
ma  "a mano" va...
SendKeys "{ENTER}", False (o SendKeys "{ENTER}", True) : non va
ma  "a mano" va...
mai successo?

"kitesurfz"
invio dei tasti con sendkeys ad una finestrella (non mia)...
certi tasti vanno, altri no ma se li "pigio" a mano, vanno tutti.
Prova con appactivate e DoEvents
e' meglio adoperare il SendMessage
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As
Long, lParam As Any) As Long
tutto su :
scarica API-GUIDE
http://www.mentalis.org/agnet/apiguide.shtml
http://www.mentalis.org/agnet/appdown.shtml
http://www.mentalis.org/index2.shtml
--
Fosco

> vi č mai successo?
No, ma temo che possa accadere se invii una sequenza: se prima gli invii
un comando per aprire un menu (tipo ALT-F) e non attendi che il menu
compaia, una sequenza successiva non ha l'effetto desiderato in quanto
il messaggio viene perduto...
-- 
Quando noi ignoranti eravamo di piů, tutto era piů bello...
(A. Celentano)
Per rispondermi in privato, prima togli l'immondizia dalla testa ;)

la appactivate la faccio già.
la sendmessage boh? non so come trovare hwnd, perchè la finestrella
non la gestisco io

dovrebbe bastare fare sendmessage xxxx, True. il True "fa aspettare"
comunque ho provato anche a mettere anche uno sleep 5000, ma non basta.

ma  "a mano" va...
Prova questo codice:
http://www.freevbcode.com/ShowCode.Asp?ID=340
ciao
  Stefano

"kitesurfz"
scolta ti metto un "coso" che adoperavo per
fare esperimenti .... e' PARECCHIO pasticciato e adesso
non ho il tempo di pulirlo ma ci sono tutte le basi di SendKeys
e SendMessage
alcune linee sono commentate perche' dovevo farlo andare
su Win98 e NON XP (se ti interessa XP dovrei avere anche quello)
basta un Command Button e copiare tutto su 1 form :
Private lhWndNotepad As Long
Private Const WM_SETTEXT = &HC
Private Const BM_CLICK = &HF5
Private Const WM_CLOSE = &H10
Private Const WM_COMMAND = &H111
'Private Const WM_LBUTTONUP = &H202
Private Const BN_CLICKED = 0
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal
wParam As Long, lParam As Any) As Long
'sendmessage declared with lParam ByVal
Private Declare Function SendMessage2 Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function lSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long,
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As
String) As Long
Private Sub ClickMenu(lMenu As Long, lItem As Long)
    'Dim lMenu     As Long
    Dim lSubMenu  As Long
    Dim lMenuItem As Long
    lMenu = GetMenu(lhWndNotepad)
    lSubMenu = GetSubMenu(lMenu, lMenu)
    lMenuItem = GetMenuItemID(lSubMenu, lItem)
    Call PostMessage(lhWndNotepad, WM_COMMAND, lMenuItem, 0)
    'sendmessage would hang app until file is selected in open form but
    'postmessage is asynchronous which is better in this case
End Sub
Private Function GetWindowHandle(ps_WindowTitle As String) As Long
    GetWindowHandle = FindWindow(vbNullString, ps_WindowTitle)
End Function
Private Sub StartNotePad()
    Call Shell("notepad", vbNormalFocus)
    DoEvents
    Do While lhWndNotepad = 0
        lhWndNotepad = GetWindowHandle("Senza nome - Blocco note")
    Loop
End Sub
Private Sub CloseNotePad()
    Call SendMessage(lhWndNotepad, WM_CLOSE, 0, 0)
End Sub
Private Sub Command1_Click()
Simulate
End Sub
Private Sub Form_Load()
  '  StartNotePad
   ' Show
   ' SetFocus
End Sub
Private Sub SetNotePadInForeground()
    SetForegroundWindow lhWndNotepad
End Sub
Private Sub Form_Unload(Cancel As Integer)
    CloseNotePad
End Sub
Private Sub Simulate()
StartNotePad
    Show
    SetFocus
    Dim hMsgBox As Long
    Dim hTextBox As Long
    Dim hComboBox As Long
    Dim hComboBox2 As Long
    'activate notepad
    SetNotePadInForeground
    'open file menu
    SendKeys "%F"
    Wait
    'simulate down key
    SendKeys "{Down}"
    Wait
    'ClickMenu 0, 1
    SendKeys "{Enter}"
    'wait until the dialog appears
    Do While hMsgBox = 0 Or lCount > 5000
        lCount = lCount + 1
        'hMsgBox = FindWindow("#32770", "Open")
        hMsgBox = FindWindow("#32770", "Apri")
        DoEvents
    Loop
    If hMsgBox = 0 Then Stop
    Wait
    'find ComboBoxEx32
   ' hComboBox = FindWindowEx(hMsgBox, 0, "ComboBox", "")
    hComboBox = FindWindowEx(hMsgBox, 0, "Edit", "")
   Debug.Print hComboBox
    'find the combo box within that
   ' hComboBox2 = FindWindowEx(hComboBox, 0, "ComboBox", "")
    'Debug.Print hComboBox2
    'find the textbox within that...
    'hTextBox = FindWindowEx(hComboBox, 0, "Edit", "")
  ' Debug.Print hTextBox
   ' If hTextBox = 0 Then Stop
    'set the textbox's value to the app path
    'note we use SendMessage2, which has lParam declared ByVal
   ' SendMessage2 hTextBox, WM_SETTEXT, 0, App.Path & Chr$(0)
    SendMessage2 hComboBox, WM_SETTEXT, 0, App.Path & Chr$(0)
    'simulate clicking the open button
    ClickOpen hMsgBox
    Wait
    'set the textbox's value to readme.txt
    'Debug.Print SendMessage2(hTextBox, WM_SETTEXT, 0, "readme.txt" & Chr$(0))
   Debug.Print SendMessage2(hComboBox, WM_SETTEXT, 0, "readme.txt" & Chr$(0))
    Wait
    'simulate clicking...
    ClickOpen hMsgBox
End Sub
Private Sub Wait()
    DoEvents
    Sleep 500
End Sub
Private Sub ClickOpen(hMsgBox As Long)
    Dim hButtonOpen As Long
    Dim hComboBox As Long
    hButtonOpen = FindWindowEx(hMsgBox, 0, "Button", "&Apri")
   ' hComboBox = FindWindowEx(hMsgBox, 0, "ComboBox", "")
   hComboBox = FindWindowEx(hMsgBox, 0, "Edit", "")
    If hButtonOpen = 0 Then Stop
    SendMessage hButtonOpen, BM_CLICK, 0, 0
End Sub
--
Fosco

 scolta ti metto un "coso"
ahhh l'originale  e' di James Crowley
--
Fosco