Imaginsystems


Tecniche di Programmazione - Codici Sorgenti - News Informatiche
Archivio Posts
Anno 2014

Anno 2013

Anno 2012
Statistiche
  • Views Home Page: 71.612
  • Views Posts: 542.376
  • Views Gallerie: 0
  • n° Posts: 210
  • n° Commenti: 224

VB.NET - FUNZIONE CHE APRE IL PROGRAMMA DELLA CALCOLATRICE E SIMULA LA PRESSIONE DEI NUMERI (CODICE)

 VB.NET - FUNZIONE CHE APRE IL PROGRAMMA DELLA CALCOLATRICE E SIMULA LA PRESSIONE DEI NUMERI (DA CODICE)

 

Oggi vi voglio parlare di come aprire il programma Calcolatrice (Calc.exe) e simulare la pressione dei tasti e ottenere un risultato, tutto grazie alla fantastica libreria  System.Windows.Forms.SendKeys.SendWait() .

Prima di iniziare dobbiamo verificare che nei riferimenti abbiamo inserito  System.Windows.Forms e dobbiamo fare anche importare la libreria Imports System.Windows.Forms.

Esempio di richiamo della funzione :
 
EseguiCalcolatriceProgramma(1, Operazione.Somma, 2) ' 1+2=3
        EseguiCalcolatriceProgramma(1, Operazione.Sottrazione, 2) '1-2=-1
        EseguiCalcolatriceProgramma(1, Operazione.Moltiplicazione, 2) '1*2=2
        EseguiCalcolatriceProgramma(1, Operazione.Divisione, 2) '1/2=0.5

Tabella dei comandi Simulazione dei tasti "SendKeys Representations of Common Keys"

Key

SendKeys Representation

BACKSPACE

{BACKSPACE}, {BS}, or {BKSP}

BREAK

{BREAK}

CAPS LOCK

{CAPSLOCK}

DEL or DELETE

{DELETE} or {DEL}

DOWN ARROW

{DOWN}

END

{END}

ENTER

{ENTER} or ~

ESC

{ESC}

HELP

{HELP}

HOME

{HOME}

INS or INSERT

{INSERT} or {INS}

LEFT ARROW

{LEFT}

NUM LOCK

{NUMLOCK}

PAGE DOWN

{PGDN}

PAGE UP

{PGUP}

PRINT SCREEN

{PRTSC}

RIGHT ARROW

{RIGHT}

SCROLL LOCK

{SCROLLLOCK}

TAB

{TAB}

UP ARROW

{UP}

SHIFT

+

CONTROL

^

ALT

%

BACKSPACE

{BACKSPACE}, {BS}, or {BKSP}


CODICE VISUAL STUDIO 2010 - VISUAL BASIC .NET - VB.NET:

Imports System.Windows.Forms
Imports System.Windows.Forms.KeyEventArgs

Public Class CalcolatriceEseguiCalcoli

 Public Enum Operazione As Integer
        Somma = 0
        Sottrazione = 1
        Divisione = 2
        Moltiplicazione = 3
    End Enum

    Public Function EseguiCalcolatriceProgramma(ByVal Valore1 As Integer, ByVal ValoreOperazione As Operazione, ByVal Valore2 As Integer)
        Try
            Dim myProcesso As System.Diagnostics.Process

            myProcesso = System.Diagnostics.Process.Start("calc.exe")

            myProcesso.WaitForInputIdle(1000)
            AppActivate(myProcesso.Id)

            System.Windows.Forms.SendKeys.SendWait(Valore1)
            Select ValoreOperazione
                Case Operazione.Somma
                    System.Windows.Forms.SendKeys.SendWait("{ADD}")
                Case Operazione.Sottrazione
                    System.Windows.Forms.SendKeys.SendWait("{SUBTRACT}")
                Case Operazione.Moltiplicazione
                    System.Windows.Forms.SendKeys.SendWait("{MULTIPLY}")
                Case Operazione.Divisione
                    System.Windows.Forms.SendKeys.SendWait("{DIVIDE}")
                Case Else
                    System.Windows.Forms.SendKeys.SendWait("{ADD}")
            End Select

            System.Windows.Forms.SendKeys.SendWait(Valore2)
            System.Windows.Forms.SendKeys.SendWait("{ENTER}")
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
End Class
Categoria: VB.NET
lunedì, 16 lug 2012 Ore. 18.55

Messaggi collegati


Ora e Data
Mappa
Blogs Amici
    Copyright © 2002-2007 - Blogs 2.0
    dotNetHell.it | Home Page Blogs
    ASP.NET 2.0 Windows 2003