Oppure

Loading
13/10/10 21:17
gecko6989
Ciao a tutti,
sto realizzando una tastiera su schermo identica a quella incorporata in windows....
Premetto che per fare ci sto usando il metodo sendkeys.

Il programma funge con una textbox perchè faccio:
 Private Sub Cmd01_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmd01.Click
        TextBox1.Focus()

        My.Computer.Keyboard.SendKeys("A", True)
    End Sub


Il problema sta nel fatto che quando voglio scrivere su un blocco note non ci riesco....perchè?


aaa
13/10/10 22:09
gecko6989
Ho risolto con un codice trovate sul web:


Imports System.Runtime.InteropServices

Public Class Form1

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetForegroundWindow() As IntPtr
    End Function
    <DllImport("user32.dll")> _
    Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function


    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Timer1.Interval = 100
        Timer1.Start()
    End Sub
    Private window As IntPtr
    Private Sub Timer1_Tick _
        (ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles Timer1.Tick
        Dim iptr As IntPtr = GetForegroundWindow()
        If (iptr <> Me.Handle) Then window = iptr
    End Sub


    Private Sub Cmd01_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmd01.Click
        SetForegroundWindow(window)
        My.Computer.Keyboard.SendKeys("A")
    End Sub
End Class



Qualcuno è in grado di spiegarmi come funziona?
Sopratutto, è possibile semplificare questo codice?
aaa
14/10/10 11:31
Il Totem
La SendKeys serve proprio da wrapper per evitare di accedere all'api, quindi mi sembra strano che non funzioni. Se sei disperato, puoi provare la funzione keydb_event o la più recente SendInput definite nella user32.dll.
aaa