Quote:
Originariamente inviato da Dante92
io avrei intenzione di realizzare un programma che tenendo premuto il tasto sinistro simuli ad esempio il doppio click a livello globale del sistema
|
Detto fatto,

, personalmente la risolverei così :
Codice:
Public Class Form1
Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
Private Const vKeyPSinistro = 1 'Click Sinistro
Private Const ticksPerDoubleClick As Integer = 10
Private timerTicks As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GetAsyncKeyState(vKeyPSinistro) Then
timerTicks += 1
If timerTicks = ticksPerDoubleClick Then 'Doppio Click
'&H2 = MouseDown sinistro
'&H4 = MouseUp sinistro
mouse_event(&H2, 0, 0, 0, 1)
mouse_event(&H4, 0, 0, 0, 1)
mouse_event(&H2, 0, 0, 0, 1)
mouse_event(&H4, 0, 0, 0, 1)
timerTicks = 0
End If
Else
timerTicks = 0
End If
End Sub
End Class
Nel mio esempio ho Timer1 con intervallo = 100.
ticksPerDoubleClick decide quanti scatti fa il Timer prima che una pressione continuata del tasto sinistro venga interpretata come doppio-click.
Con ticksPerDoubleClick = 10 il tempo necessario sarà appunto :
ticksPerDoubleClick * Timer1.Interval = 10 * 100 = 1 secondo.
Se mi posiziono ad es. su un file di testo sul desktop e tengo premuto il tasto sinistro per 1 sec, scateno il doppio click e il file .txt si apre... Prova.