VIAF - Virtual Italian Air Force: Forum

VIAF :: Leggi il Topic - Visual basic per inviare macro verso Falcon AF
 
 FAQFAQ   CercaCerca   Lista degli utentiLista degli utenti   Gruppi utentiGruppi utenti 
 ProfiloProfilo   Messaggi PrivatiMessaggi Privati   LoginLogin 
Visual basic per inviare macro verso Falcon AF
Vai a pagina 1, 2  Successivo
 
Questo forum è chiuso. Non puoi inserire, rispondere o modificare i Topics   Topic chiuso    Indice del forum :: Developers' Corner
Precedente :: Successivo  
Autore Messaggio
firefox
pilota
pilota



Registrato: Aug 04, 2006
Messaggi: 419
Località: Vicenza
 

MessaggioInviato: Mar Gen 06, 2009 19.05    Oggetto: Visual basic per inviare macro verso Falcon AF Rispondi citando

Vorrei fare una domanda.
Stiamo cercando attraverso Visual Basic di interfacciare dei PIC per inviare delle macro al simulatore.
Come primo passo vogliamo vedere se compilando un piccolo programma in Visual Basic è possibile inviare al PC delle combinazioni di tasti che corrispondano a delle macro riconosciute da Falcon.

Se ad esempio diciamo al programma in VB di simulare l'invio della lettera G, osserviamo su un blocco note aperto l'effettiva comparsa della lettera "G".... e lo stesso vale per altre combinazioni di tasti e macro..

Il punto è che la stessa sequenza di tasti indirizzata via VB non sortisce nessun effetto su Falcon....

Sarà mica che VB non è adatto a Falcon o che Falcon non può ricevere input da VB???

O c'è qualche file strano da editare???
Vi prego aiutatemi.
Grazie.
Torna in cima
Profilo Messaggio privato Invia email Numero ICQ
Spinter
Dr.Cougar!
Dr.Cougar!



Registrato: May 20, 2004
Messaggi: 2737
Località: Resia (Udine)
Regione: Friuli-Venezia Giulia

MessaggioInviato: Mar Gen 06, 2009 19.23    Oggetto: Rispondi citando

Allora sto facendo delle prove proprio in questi giorni per il mio pit per falcon,non ho avuto grandi risultati,motivo perchè non ho il secondo pc per provare(al momento senza alimentatore).
Se hai la pazienza posso aiutarti ma mi ci vogliono un paio di settimane per risolvere dei problemi.
Ti lascio questi link dove ne parlano.
io avevo fatto un proggetto ma non riesco a trovarlo e mi funzionava bene!!!

http://msdn.microsoft.com/it-it/library/ms171534(VS.85).aspx
http://msdn.microsoft.com/it-it/library/ms171548(VS.85).aspx
http://www.pierotofy.it/pages/guide_tutorials/Visual_Basic/Simulare_mouse_e_tastiera_da_codice/
_________________


Mag. Spinter 155° Pantere Nere VIAF
http://www.aiupgrade.net ICQ 224397155
Grande Udinese (Per Roby)
Torna in cima
Profilo Messaggio privato HomePage Numero ICQ
max10891
e...piantala di postare!
e...piantala di postare!
a.k.a: Zaino


Registrato: Jun 09, 2005
Messaggi: 2251
Località: sovico(MI)
Regione: Lombardia

MessaggioInviato: Mar Gen 06, 2009 20.50    Oggetto: Rispondi citando

m...premetto che in VB non so nulla o quasi...

ma non ho capito il tuo problema...

hai questo programmino che se lo lanci facendolo scrivere su un blocco note ti scrive la giusta combinazione se lo lanci verso falcon non la fa?

in che modo è interfacciato con falcon e con il blocco note?
_________________

Esist
Torna in cima
Profilo Messaggio privato Invia email MSN Messenger Numero ICQ
firefox
pilota
pilota



Registrato: Aug 04, 2006
Messaggi: 419
Località: Vicenza
 

MessaggioInviato: Mar Gen 06, 2009 22.37    Oggetto: Rispondi citando

Dunque, vediamo....
Ho la fortuna di avere un collaboratore esperto in programmazione che voleva avventurarsi nella programmazione di microcontroller tramite delle routines di VB.

Quindi il programmino lo stiamo, anzi lo stà scrivendo.
Io sebbene conosca abbastanza bene MFS non conosco molto Falcon, quindi non posso aiutarlo molto...

Oggi aveva compilato un programma di "eventi", ove ogni 2 secondi simulava la combinazione di uno o più tasti....

Lanciava questo programmino di eventi e sul notepad le letterine venivano a mano a mano scritte....

Con MFS tutto a posto, carrello e luci che si attivavano che erano una bellezza!!

Ma con Falcon niente.
Il programma parte e si vede che stà generando combinazioni di tasti ma quelle combinazioni che se digitate direttamente dalla tastiera azionano dei comandi in Falcon, non hanno effetti se generate dal software.

Cosa stiamo sbagliando???

Spero che presto si possa approfondire l'argomento direttamente con lui.
Per quanto riguarda il tempo, no problem.
Io stò approntando il mio pit, quindi non ho nessuna fretta.

In che senso il progetto di Spinter, funzionava bene??

Ciao...
Torna in cima
Profilo Messaggio privato Invia email Numero ICQ
DaveDevil
pinguino
pinguino



Registrato: Dec 02, 2008
Messaggi: 7

 

MessaggioInviato: Gio Gen 08, 2009 00.35    Oggetto: Rispondi citando

Ciao a tutti!

Io sono Davide...


« firefox » ha scritto:
Ho la fortuna di avere un collaboratore esperto in programmazione che voleva avventurarsi nella programmazione di microcontroller tramite delle routines di VB.


questo dovrei essere io Embarassed anche se esperto non lo sono, in quanto autodidatta in VB.Net Rolling Eyes

Piccolo progettista elettronico, più che altro per hobby, per una serie di fortunate coincidenze mi trovo ad avere alcuni dei miei progetti (non inerenti alla costruzione di cockpit) in sintonia con Firefox.

E vi spiego anche meglio cosa intendo precisamente:

1. Comunicazione tra un'interfaccia a microcontrollore (PIC) ed il computer (Visual Basic)
2. Comunicazione tra l'interfaccia HW connessa al pc, con altre (indefinite) periferiche "figlie"
3. Possibilità di fare interagire i miei programmi in Visual Basic con altri programmi esterni, in particolare tramite "macro" da tastiera.

« firefox » ha scritto:
Quindi il programmino lo stiamo, anzi lo stà scrivendo.
Io sebbene conosca abbastanza bene MFS non conosco molto Falcon, quindi non posso aiutarlo molto...

Oggi aveva compilato un programma di "eventi", ove ogni 2 secondi simulava la combinazione di uno o più tasti....

Lanciava questo programmino di eventi e sul notepad le letterine venivano a mano a mano scritte....

Con MFS tutto a posto, carrello e luci che si attivavano che erano una bellezza!!

Ma con Falcon niente.
Il programma parte e si vede che stà generando combinazioni di tasti ma quelle combinazioni che se digitate direttamente dalla tastiera azionano dei comandi in Falcon, non hanno effetti se generate dal software.

Cosa stiamo sbagliando???

Spero che presto si possa approfondire l'argomento direttamente con lui.


A questo proposito siamo nel punto 3, quindi cerco di spiegare meglio i miei test.

Utilizzo VB.NET, parte di Visual Studio 2008, quindi l'ultima versione del linguaggio Basic.net.

Qui è implementata una funzione "SENDKEY" che mi permette di inviare un tasto come se fosse stato premuto da tastiera, ma Microsoft stessa, nelle guide online, spiega chiaramente che NON E' come premere i tasti da tastiera.

Ecco spiegato il fatto che sul blocco note i caratteri apparivano, su FS i comandi funzionano (ovvio, FS è Microsoft!) mentre altri programmi come Falcon (che interessa a Firefox) o Dragon Naturally Speaking (che interessa a me) non ricevono queste combinazioni.

Più precisamente, la mia prova è stata di inviare, con pause di due secondi, sequenze semplici e/o complesse di tasti, da una singola "g" per muovere il carrello, a tasti macro come CTRL-E che se non ricordo male è l'avvio dei motori in FS2004.


« Spinter » ha scritto:
Allora sto facendo delle prove proprio in questi giorni per il mio pit per falcon,non ho avuto grandi risultati,motivo perchè non ho il secondo pc per provare(al momento senza alimentatore).
Se hai la pazienza posso aiutarti ma mi ci vogliono un paio di settimane per risolvere dei problemi.
Ti lascio questi link dove ne parlano.
io avevo fatto un proggetto ma non riesco a trovarlo e mi funzionava bene!!!

http://msdn.microsoft.com/it-it/library/ms171534(VS.85).aspx
http://msdn.microsoft.com/it-it/library/ms171548(VS.85).aspx
http://www.pierotofy.it/pages/guide_tutorials/Visual_Basic/Simulare_mouse_e_tastiera_da_codice/


Allora, i primi due link sono proprio la descrizione del comando SendKey che ho utilizzato finora...

il terzo invece, parla dell'utilizzo delle API di windows, cosa molto diversa e (probabilmente) che potrà dare i risultati sperati...


Altri suggerimenti su come "dare in pasto" a Falcon dei comandi generabili con Visual Basic sono graditi Very Happy

In questo preciso momento mi sto informando meglio sull'utilizzo delle API, come dal terzo link...
Torna in cima
Profilo Messaggio privato
Spinter
Dr.Cougar!
Dr.Cougar!



Registrato: May 20, 2004
Messaggi: 2737
Località: Resia (Udine)
Regione: Friuli-Venezia Giulia

MessaggioInviato: Gio Gen 08, 2009 16.52    Oggetto: Rispondi citando

fammi sapere se trovi prima di me mi sto spaccando la testa!!
_________________


Mag. Spinter 155° Pantere Nere VIAF
http://www.aiupgrade.net ICQ 224397155
Grande Udinese (Per Roby)
Torna in cima
Profilo Messaggio privato HomePage Numero ICQ
max10891
e...piantala di postare!
e...piantala di postare!
a.k.a: Zaino


Registrato: Jun 09, 2005
Messaggi: 2251
Località: sovico(MI)
Regione: Lombardia

MessaggioInviato: Gio Gen 08, 2009 17.51    Oggetto: Rispondi citando

non so se vi possa essere utile...
vi dico piu o meno come ho provato a usare io le API in c++...dovrebbe essere piu o meno simile

devi usare la libreria <windows.h>
e il comando per mandare una pressione del tasto è

keybd_event ()

ESEMPIO

pressione di CTRL+E

keybd_event( VK_CONTROL, 0, 0, 0 ); //preme CTRL
keybd_event( 'E', 0, 0, 0 ); //preme E
keybd_event( 'E', 0, KEYEVENTF_KEYUP, 0 ); //rilasca E
keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 ); //rilasca CTRL

il primo parametro indica il tasto da premere (qui una lista dei tasti "speciali" http://msdn.microsoft.com/en-us/library/ms645540.aspx )
il secondo l'ho sempre usato a 0 e nn ricordo il significato
il terzo è l'azione tipo rilascia
il quarto pure lui non lo ricordo e anche lui l'ho sempre lasciato a 0



spero vi possa servire un pochino...
_________________

Esist
Torna in cima
Profilo Messaggio privato Invia email MSN Messenger Numero ICQ
firefox
pilota
pilota



Registrato: Aug 04, 2006
Messaggi: 419
Località: Vicenza
 

MessaggioInviato: Gio Gen 08, 2009 22.21    Oggetto: Rispondi citando

....grassie....
Torna in cima
Profilo Messaggio privato Invia email Numero ICQ
Spinter
Dr.Cougar!
Dr.Cougar!



Registrato: May 20, 2004
Messaggi: 2737
Località: Resia (Udine)
Regione: Friuli-Venezia Giulia

MessaggioInviato: Sab Gen 10, 2009 14.07    Oggetto: Rispondi citando

 

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace LightningSamples
{
    public class KeyAndMouseUtils
    {
        internal enum INPUT_TYPE : uint
        {
            INPUT_MOUSE = 0,
            INPUT_KEYBOARD = 1,
            INPUT_HARDWARE = 2,
        }

        [Flags()]
        internal enum KEYEVENTF : uint
        {
            EXTENDEDKEY = 0x0001,
            KEYUP = 0x0002,
            UNICODE = 0x0004,
            SCANCODE = 0x0008,
        }
        internal enum MAPVK_MAPTYPES : uint
        {
            MAPVK_VK_TO_VSC = 0x0,
            MAPVK_VSC_TO_VK = 0x1,
            MAPVK_VK_TO_CHAR = 0x2,
            MAPVK_VSC_TO_VK_EX = 0x3,
            MAPVK_VK_TO_VSC_EX = 0x4,
        }
        [Flags()]
        internal enum MOUSEEVENTF : uint
        {
            MOVE = 0x0001,  // mouse move
            LEFTDOWN = 0x0002,  // left button down
            LEFTUP = 0x0004,  // left button up
            RIGHTDOWN = 0x0008,  // right button down
            RIGHTUP = 0x0010,  // right button up
            MIDDLEDOWN = 0x0020,  // middle button down
            MIDDLEUP = 0x0040,  // middle button up
            XDOWN = 0x0080,  // x button down
            XUP = 0x0100,  // x button down
            WHEEL = 0x0800,  // wheel button rolled
            VIRTUALDESK = 0x4000,  // map to entire virtual desktop
            ABSOLUTE = 0x8000,  // absolute move
        }

        [StructLayout(LayoutKind.Sequential)]
        internal struct MOUSEINPUT
        {
            public int dx;
            public int dy;
            public uint mouseData;
            public MOUSEEVENTF dwFlags;
            public uint time;
            public UIntPtr dwExtraInfo;
        }
        [StructLayout(LayoutKind.Sequential)]
        internal struct HARDWAREINPUT
        {
            public uint uMsg;
            public ushort wParamL;
            public ushort wParamH;
        }
        [StructLayout(LayoutKind.Sequential)]
        internal struct KEYBDINPUT
        {
            public ushort wVk;
            public ushort wScan;
            public KEYEVENTF dwFlags;
            public uint time;
            public IntPtr dwExtraInfo;
        }
        [StructLayout(LayoutKind.Explicit)]
        internal struct INPUT
        {
            [FieldOffset(0)]
            public INPUT_TYPE type;
            [FieldOffset(4)]
            public MOUSEINPUT mi;
            [FieldOffset(4)]
            public KEYBDINPUT ki;
            [FieldOffset(4)]
            public HARDWAREINPUT hi;
        }

        [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, EntryPoint = "MapVirtualKey", SetLastError = false)]
        internal static extern uint MapVirtualKey(uint uCode, MAPVK_MAPTYPES uMapType);

        [DllImport("user32.dll")]
        internal static extern IntPtr GetMessageExtraInfo();
       
        [DllImport("user32.dll", SetLastError = true)]
        internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
       
        [DllImportAttribute("User32.dll", SetLastError = true)]
        internal static extern IntPtr FindWindow(String ClassName, String WindowName);
       
        [DllImportAttribute("User32.dll", SetLastError = true)]
        internal static extern bool SetForegroundWindow(IntPtr hWnd);

        internal static void SendMouseInput(MOUSEEVENTF dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo)
        {
            INPUT input = new INPUT();
            input.mi = new MOUSEINPUT();
            input.type = INPUT_TYPE.INPUT_MOUSE;
            input.mi.dwFlags = dwFlags;
            input.mi.dx = (int)dx;
            input.mi.dy = (int)dy;
            input.mi.mouseData = dwData;
            input.mi.time = 0;
            input.mi.dwExtraInfo = dwExtraInfo;
            SendInput(1, new INPUT[] { input }, Marshal.SizeOf(typeof(INPUT)));
        }

        public static void SendKeyInput(Keys keys, bool press, bool release)
        {
            if (!press && !release)
            {
                return;
            }

            int numInputs = 0;
            if (press && release)
            {
                numInputs = 2;
            }
            else
            {
                numInputs = 1;
            }
            INPUT[] inputs = new INPUT[numInputs];
            int curInput = 0;
            if (press)
            {
                INPUT input = new INPUT();
                input.ki = new KEYBDINPUT();
                ushort scanCode = (ushort)MapVirtualKey((uint)(keys & Keys.KeyCode), MAPVK_MAPTYPES.MAPVK_VK_TO_VSC);
                input.ki.wScan = scanCode;
                input.ki.time = 0;
                input.ki.dwFlags = KEYEVENTF.SCANCODE;
                if (((int)(keys & Keys.KeyCode) & 0xE000) > 0)
                {
                    input.ki.dwFlags |= KEYEVENTF.EXTENDEDKEY;
                }
                input.ki.dwExtraInfo = GetMessageExtraInfo();
                input.type = INPUT_TYPE.INPUT_KEYBOARD;
                inputs[curInput] = input;
                curInput++;
            }
            if (release)
            {
                INPUT input = new INPUT();
                input.ki = new KEYBDINPUT();
                ushort scanCode = (ushort)MapVirtualKey((uint)(keys & Keys.KeyCode), MAPVK_MAPTYPES.MAPVK_VK_TO_VSC);
                input.ki.wScan = scanCode;
                input.ki.time = 0;
                input.ki.dwFlags = (KEYEVENTF.KEYUP | KEYEVENTF.SCANCODE);
                if (((int)(keys & Keys.KeyCode) & 0xE000) > 0)
                {
                    input.ki.dwFlags |= KEYEVENTF.EXTENDEDKEY;
                }
                input.ki.dwExtraInfo = GetMessageExtraInfo();
                input.type = INPUT_TYPE.INPUT_KEYBOARD;
                inputs[curInput] = input;
            }
            SendInput((uint)numInputs, inputs, Marshal.SizeOf(typeof(INPUT)));

        }

        public static void SendKeyInputToFalcon(Keys keys, bool press, bool release)
        {
            IntPtr falconWindow = FindWindow("FalconDisplay", null);
            SetForegroundWindow(falconWindow);
            SendKeyInputToFalcon(keys, press, release);
        }

        /// <summary>
        ///Moves the mouse to the given relative (x,y) coordinates.
        /// </summary>
        public static void MouseMoveRelative(int x, int y)
        {
            int cur_x = Cursor.Position.X;
            int cur_y = Cursor.Position.Y;

            int new_x = cur_x + x;
            int new_y = cur_y + y;
            MouseMoveAbsolute(new_x, new_y);
        }

        /// <summary>
        ///Moves the mouse to the given absolute (x,y) coordinates.
        /// </summary>
        public static void MouseMoveAbsolute(int x, int y)
        {
            x = x * 65535 / Screen.PrimaryScreen.Bounds.Width;
            y = y * 65535 / Screen.PrimaryScreen.Bounds.Height;
            SendMouseInput((MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.MOVE), (uint)x, (uint)y, (uint)0, UIntPtr.Zero);
        }
        /// <summary>
        ///Moves the mouse wheel by given amount.
        /// </summary>
        public static void MouseWheelMove(int amount)
        {
            SendMouseInput(MOUSEEVENTF.WHEEL, (uint)0, (uint)0, (uint)amount, UIntPtr.Zero);
        }


        /// <summary>
        ///Sends a left mouse button up event at the current cursor position.
        /// </summary>
        public static void LeftUp()
        {
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero);
        }

        /// <summary>
        ///Sends a right mouse button up event at the current cursor position.
        /// </summary>
        public static void RightUp()
        {
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero);
        }


        /// <summary>
        ///Sends a middle mouse button up event at the current cursor position.
        /// </summary>
        public static void MiddleUp()
        {
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero);
        }


        /// <summary>
        ///Sends a middle mouse button down event at the current cursor position.
        /// </summary>
        public static void MiddleDown()
        {
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero);
        }

        /// <summary>
        ///Sends a right mouse button down event at the current cursor position.
        /// </summary>
        public static void RightDown()
        {
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero);
        }

        /// <summary>
        ///Sends a left mouse button down event at the current cursor position.
        /// </summary>
        public static void LeftDown()
        {
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero);
        }


        /// <summary>
        ///Sends a middle mouse button double click at the current cursor position.
        /// </summary>
        public static void MiddleDoubleClick()
        {
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
        }


        /// <summary>
        ///Sends a right mouse button double click at the current cursor position.
        /// </summary>
        public static void RightDoubleClick()
        {
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
        }


        /// <summary>
        ///Sends a left mouse button double click at the current cursor position.
        /// </summary>
        public static void LeftDoubleClick()
        {
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
        }


        /// <summary>
        ///Sends a right mouse button click at the current cursor position.
        /// </summary>
        public static void RightClick()
        {
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
        }


        /// <summary>
        ///Sends a left mouse button click at the current cursor position.
        /// </summary>
        public static void LeftClick()
        {
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
        }

        /// <summary>
        ///Sends a middle mouse button click at the current cursor position.
        /// </summary>
        public static void MiddleClick()
        {
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(100);
        }

    }
}





Questo codice scritto in C basterebbe capirci qualchecosa di C ,io sto provando!!!


http://www.viperpits.org/smf/index.php?topic=4432.0
_________________


Mag. Spinter 155° Pantere Nere VIAF
http://www.aiupgrade.net ICQ 224397155
Grande Udinese (Per Roby)
Torna in cima
Profilo Messaggio privato HomePage Numero ICQ
max10891
e...piantala di postare!
e...piantala di postare!
a.k.a: Zaino


Registrato: Jun 09, 2005
Messaggi: 2251
Località: sovico(MI)
Regione: Lombardia

MessaggioInviato: Sab Gen 10, 2009 17.49    Oggetto: Rispondi citando

public static void SendKeyInput(Keys keys, bool press, bool release)
        {
            if (!press && !release)
            {
                return;
            }

            int numInputs = 0;
            if (press && release)
            {
                numInputs = 2;
            }
            else
            {
                numInputs = 1;
            }
            INPUT[] inputs = new INPUT[numInputs];
            int curInput = 0;
            if (press)
            {
                INPUT input = new INPUT();
                input.ki = new KEYBDINPUT();
                ushort scanCode = (ushort)MapVirtualKey((uint)(keys & Keys.KeyCode), MAPVK_MAPTYPES.MAPVK_VK_TO_VSC);
                input.ki.wScan = scanCode;
                input.ki.time = 0;
                input.ki.dwFlags = KEYEVENTF.SCANCODE;
                if (((int)(keys & Keys.KeyCode) & 0xE000) > 0)
                {
                    input.ki.dwFlags |= KEYEVENTF.EXTENDEDKEY;
                }
                input.ki.dwExtraInfo = GetMessageExtraInfo();
                input.type = INPUT_TYPE.INPUT_KEYBOARD;
                inputs[curInput] = input;
                curInput++;
            }
            if (release)
            {
                INPUT input = new INPUT();
                input.ki = new KEYBDINPUT();
                ushort scanCode = (ushort)MapVirtualKey((uint)(keys & Keys.KeyCode), MAPVK_MAPTYPES.MAPVK_VK_TO_VSC);
                input.ki.wScan = scanCode;
                input.ki.time = 0;
                input.ki.dwFlags = (KEYEVENTF.KEYUP | KEYEVENTF.SCANCODE);
                if (((int)(keys & Keys.KeyCode) & 0xE000) > 0)
                {
                    input.ki.dwFlags |= KEYEVENTF.EXTENDEDKEY;
                }
                input.ki.dwExtraInfo = GetMessageExtraInfo();
                input.type = INPUT_TYPE.INPUT_KEYBOARD;
                inputs[curInput] = input;
            }
            SendInput((uint)numInputs, inputs, Marshal.SizeOf(typeof(INPUT)));

        }

        public static void SendKeyInputToFalcon(Keys keys, bool press, bool release)
        {
            IntPtr falconWindow = FindWindow("FalconDisplay", null);
            SetForegroundWindow(falconWindow);
            SendKeyInputToFalcon(keys, press, release);
        }


questa dovrebbe essere la parte relativa alla tastiera
_________________

Esist
Torna in cima
Profilo Messaggio privato Invia email MSN Messenger Numero ICQ
DaveDevil
pinguino
pinguino



Registrato: Dec 02, 2008
Messaggi: 7

 

MessaggioInviato: Lun Gen 12, 2009 09.43    Oggetto: Rispondi citando

esatto, questo è quello che sto tentando di utilizzare!

ho fatto una prova veloce e pare funzionare con programmi "non-microsoft", ora ho quasi finito un programma di test da far provare a firefox con Falcon, ci dirà lui i risultati Wink
Torna in cima
Profilo Messaggio privato
firefox
pilota
pilota



Registrato: Aug 04, 2006
Messaggi: 419
Località: Vicenza
 

MessaggioInviato: Lun Gen 12, 2009 15.06    Oggetto: Rispondi citando

Laughing Crying or Very sad Crying or Very sad Laughing Laughing Laughing non vedo l'ora!!!
Torna in cima
Profilo Messaggio privato Invia email Numero ICQ
Spinter
Dr.Cougar!
Dr.Cougar!



Registrato: May 20, 2004
Messaggi: 2737
Località: Resia (Udine)
Regione: Friuli-Venezia Giulia

MessaggioInviato: Lun Gen 12, 2009 21.24    Oggetto: Rispondi citando

« DaveDevil » ha scritto:
esatto, questo è quello che sto tentando di utilizzare!

ho fatto una prova veloce e pare funzionare con programmi "non-microsoft", ora ho quasi finito un programma di test da far provare a firefox con Falcon, ci dirà lui i risultati Wink


ma scritto in che codice?
_________________


Mag. Spinter 155° Pantere Nere VIAF
http://www.aiupgrade.net ICQ 224397155
Grande Udinese (Per Roby)
Torna in cima
Profilo Messaggio privato HomePage Numero ICQ
DaveDevil
pinguino
pinguino



Registrato: Dec 02, 2008
Messaggi: 7

 

MessaggioInviato: Lun Gen 12, 2009 22.17    Oggetto: Rispondi citando

« Spinter » ha scritto:
« DaveDevil » ha scritto:
esatto, questo è quello che sto tentando di utilizzare!

ho fatto una prova veloce e pare funzionare con programmi "non-microsoft", ora ho quasi finito un programma di test da far provare a firefox con Falcon, ci dirà lui i risultati Wink


ma scritto in che codice?


Basic.net

ho mandato or ora il file a firefox...

attendo sue notizie...
Torna in cima
Profilo Messaggio privato
Spinter
Dr.Cougar!
Dr.Cougar!



Registrato: May 20, 2004
Messaggi: 2737
Località: Resia (Udine)
Regione: Friuli-Venezia Giulia

MessaggioInviato: Mer Gen 14, 2009 18.36    Oggetto: Rispondi citando

bene ci sono riuscito!!!




Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Threading
 
    Public Class KeyAndMouseUtils
        Friend Enum INPUT_TYPE As UInteger
            INPUT_MOUSE = 0
            INPUT_KEYBOARD = 1
            INPUT_HARDWARE = 2
        End Enum

        <Flags()> _
        Friend Enum KEYEVENTF As UInteger
            EXTENDEDKEY = &H1
            KEYUP = &H2
            UNICODE = &H4
            SCANCODE = &H8
        End Enum
        Friend Enum MAPVK_MAPTYPES As UInteger
            MAPVK_VK_TO_VSC = &H0
            MAPVK_VSC_TO_VK = &H1
            MAPVK_VK_TO_CHAR = &H2
            MAPVK_VSC_TO_VK_EX = &H3
            MAPVK_VK_TO_VSC_EX = &H4
        End Enum
        <Flags()> _
        Friend Enum MOUSEEVENTF As UInteger
            '&H1
            '0x1
            hit = &H2
            MOVE = &H1
            ' mouse move
            LEFTDOWN = &H2
            ' left button down
            LEFTUP = &H4
            ' left button up
            RIGHTDOWN = &H8
            ' right button down
            RIGHTUP = &H10
            ' right button up
            MIDDLEDOWN = &H20
            ' middle button down
            MIDDLEUP = &H40
            ' middle button up
            XDOWN = &H80
            ' x button down
            XUP = &H100
            ' x button down
            WHEEL = &H800
            ' wheel button rolled
            VIRTUALDESK = &H4000
            ' map to entire virtual desktop
            ABSOLUTE = &H8000
        End Enum
        ' absolute move

        <StructLayout(LayoutKind.Sequential)> _
        Friend Structure MOUSEINPUT
            Public dx As Integer
            Public dy As Integer
            Public mouseData As UInteger
            Public dwFlags As MOUSEEVENTF
            Public time As UInteger
            Public dwExtraInfo As UIntPtr
        End Structure
        <StructLayout(LayoutKind.Sequential)> _
        Friend Structure HARDWAREINPUT
            Public uMsg As UInteger
            Public wParamL As UShort
            Public wParamH As UShort
        End Structure
        <StructLayout(LayoutKind.Sequential)> _
        Friend Structure KEYBDINPUT
            Public wVk As UShort
            Public wScan As UShort
            Public dwFlags As KEYEVENTF
            Public time As UInteger
            Public dwExtraInfo As IntPtr
        End Structure
        <StructLayout(LayoutKind.Explicit)> _
        Friend Structure INPUT
            <FieldOffset(0)> _
            Public type As INPUT_TYPE
            <FieldOffset(4)> _
            Public mi As MOUSEINPUT
            <FieldOffset(4)> _
            Public ki As KEYBDINPUT
            <FieldOffset(4)> _
            Public hi As HARDWAREINPUT
        End Structure

        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, EntryPoint:="MapVirtualKey", SetLastError:=False)> _
        Friend Shared Function MapVirtualKey(ByVal uCode As UInteger, ByVal uMapType As MAPVK_MAPTYPES) As UInteger
        End Function

        <DllImport("user32.dll")> _
        Friend Shared Function GetMessageExtraInfo() As IntPtr
        End Function

        <DllImport("user32.dll", SetLastError:=True)> _
        Friend Shared Function SendInput(ByVal nInputs As UInteger, ByVal pInputs As INPUT(), ByVal cbSize As Integer) As UInteger
        End Function

        <DllImportAttribute("User32.dll", SetLastError:=True)> _
        Friend Shared Function FindWindow(ByVal ClassName As String, ByVal WindowName As String) As IntPtr
        End Function

        <DllImportAttribute("User32.dll", SetLastError:=True)> _
        Friend Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
        End Function
        <DllImport("user32.dll")> _
        Private Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UIntPtr)
        End Sub
        Friend Shared Sub SendMouseInput(ByVal dwFlags As MOUSEEVENTF, ByVal dx As UInteger, ByVal dy As UInteger, ByVal dwData As UInteger, ByVal dwExtraInfo As UIntPtr)
            Dim input As New INPUT()
            input.mi = New MOUSEINPUT()
            input.type = INPUT_TYPE.INPUT_MOUSE
            input.mi.dwFlags = dwFlags
            input.mi.dx = CInt(dx)
            input.mi.dy = CInt(dy)
            input.mi.mouseData = dwData
            input.mi.time = 0
            input.mi.dwExtraInfo = dwExtraInfo
            SendInput(1, New INPUT() {input}, Marshal.SizeOf(GetType(INPUT)))
        End Sub

        Public Shared Sub SendKeyInput(ByVal keys__1 As Keys, ByVal press As Boolean, ByVal release As Boolean)
            If Not press AndAlso Not release Then
                Exit Sub
            End If

            Dim numInputs As Integer = 0
            If press AndAlso release Then
                numInputs = 2
            Else
                numInputs = 1
            End If
            Dim inputs As INPUT() = New INPUT(numInputs - 1) {}
            Dim curInput As Integer = 0
            If press Then
                Dim input As New INPUT()
                input.ki = New KEYBDINPUT()
                Dim scanCode As UShort = CUShort(MapVirtualKey(CUInt((keys__1 And Keys.KeyCode)), MAPVK_MAPTYPES.MAPVK_VK_TO_VSC))
                input.ki.wScan = scanCode
                input.ki.time = 0
                input.ki.dwFlags = KEYEVENTF.SCANCODE
                If (CInt((keys__1 And Keys.KeyCode)) And &HE000) > 0 Then
                    input.ki.dwFlags = input.ki.dwFlags Or KEYEVENTF.EXTENDEDKEY
                End If
                input.ki.dwExtraInfo = GetMessageExtraInfo()
                input.type = INPUT_TYPE.INPUT_KEYBOARD
                inputs(curInput) = input
                curInput += 1
            End If
            If release Then
                Dim input As New INPUT()
                input.ki = New KEYBDINPUT()
                Dim scanCode As UShort = CUShort(MapVirtualKey(CUInt((keys__1 And Keys.KeyCode)), MAPVK_MAPTYPES.MAPVK_VK_TO_VSC))
                input.ki.wScan = scanCode
                input.ki.time = 0
                input.ki.dwFlags = (KEYEVENTF.KEYUP Or KEYEVENTF.SCANCODE)
                If (CInt((keys__1 And Keys.KeyCode)) And &HE000) > 0 Then
                    input.ki.dwFlags = input.ki.dwFlags Or KEYEVENTF.EXTENDEDKEY
                End If
                input.ki.dwExtraInfo = GetMessageExtraInfo()
                input.type = INPUT_TYPE.INPUT_KEYBOARD
                inputs(curInput) = input
            End If
            SendInput(CUInt(numInputs), inputs, Marshal.SizeOf(GetType(INPUT)))

        End Sub

        Public Shared Sub SendKeyInputToFalcon(ByVal keys As Keys, ByVal press As Boolean, ByVal release As Boolean)
            Dim falconWindow As IntPtr = FindWindow("FalconDisplay", Nothing)
            SetForegroundWindow(falconWindow)
            SendKeyInputToFalcon(keys, press, release)
        End Sub

        ''' <summary>
        '''Moves the mouse to the given relative (x,y) coordinates.
        ''' </summary>
        Public Shared Sub MouseMoveRelative(ByVal x As Integer, ByVal y As Integer)
            Dim cur_x As Integer = Cursor.Position.X
            Dim cur_y As Integer = Cursor.Position.Y

            Dim new_x As Integer = cur_x + x
            Dim new_y As Integer = cur_y + y
            MouseMoveAbsolute(new_x, new_y)
        End Sub

        ''' <summary>
        '''Moves the mouse to the given absolute (x,y) coordinates.
        ''' </summary>
        Public Shared Sub MouseMoveAbsolute(ByVal x As Integer, ByVal y As Integer)
            x = x * 65535 / Screen.PrimaryScreen.Bounds.Width
            y = y * 65535 / Screen.PrimaryScreen.Bounds.Height
            SendMouseInput((MOUSEEVENTF.ABSOLUTE Or MOUSEEVENTF.MOVE), CUInt(x), CUInt(y), CUInt(0), UIntPtr.Zero)
        End Sub
        ''' <summary>
        '''Moves the mouse wheel by given amount.
        ''' </summary>
        Public Shared Sub MouseWheelMove(ByVal amount As Integer)
            SendMouseInput(MOUSEEVENTF.WHEEL, CUInt(0), CUInt(0), CUInt(amount), UIntPtr.Zero)
        End Sub


        ''' <summary>
        '''Sends a left mouse button up event at the current cursor position.
        ''' </summary>
        Public Shared Sub LeftUp()
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero)
        End Sub

        ''' <summary>
        '''Sends a right mouse button up event at the current cursor position.
        ''' </summary>
        Public Shared Sub RightUp()
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero)
        End Sub


        ''' <summary>
        '''Sends a middle mouse button up event at the current cursor position.
        ''' </summary>
        Public Shared Sub MiddleUp()
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero)
        End Sub


        ''' <summary>
        '''Sends a middle mouse button down event at the current cursor position.
        ''' </summary>
        Public Shared Sub MiddleDown()
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero)
        End Sub

        ''' <summary>
        '''Sends a right mouse button down event at the current cursor position.
        ''' </summary>
        Public Shared Sub RightDown()
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero)
        End Sub

        ''' <summary>
        '''Sends a left mouse button down event at the current cursor position.
        ''' </summary>
        Public Shared Sub LeftDown()
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero)
        End Sub


        ''' <summary>
        '''Sends a middle mouse button double click at the current cursor position.
        ''' </summary>
        Public Shared Sub MiddleDoubleClick()
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
        End Sub


        ''' <summary>
        '''Sends a right mouse button double click at the current cursor position.
        ''' </summary>
        Public Shared Sub RightDoubleClick()
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
        End Sub


        ''' <summary>
        '''Sends a left mouse button double click at the current cursor position.
        ''' </summary>
        Public Shared Sub LeftDoubleClick()
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
        End Sub


        ''' <summary>
        '''Sends a right mouse button click at the current cursor position.
        ''' </summary>
        Public Shared Sub RightClick()
            SendMouseInput(MOUSEEVENTF.RIGHTDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.RIGHTUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
        End Sub


        ''' <summary>
        '''Sends a left mouse button click at the current cursor position.
        ''' </summary>
        Public Shared Sub LeftClick()
            SendMouseInput(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.LEFTUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
        End Sub

        ''' <summary>
        '''Sends a middle mouse button click at the current cursor position.
        ''' </summary>
        Public Shared Sub MiddleClick()
            SendMouseInput(MOUSEEVENTF.MIDDLEDOWN, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
            SendMouseInput(MOUSEEVENTF.MIDDLEUP, 0, 0, 0, UIntPtr.Zero)
            Thread.Sleep(100)
        End Sub


        Friend Shared Sub SendKeyInput()
        SendKeyInput()
        End Sub
    End Class


 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'KeyAndMouseUtils.LeftClick()
        KeyAndMouseUtils.SendKeyInput(Keys.B, 1, 1)
    End Sub






_________________


Mag. Spinter 155° Pantere Nere VIAF
http://www.aiupgrade.net ICQ 224397155
Grande Udinese (Per Roby)
Torna in cima
Profilo Messaggio privato HomePage Numero ICQ
Mostra prima i messaggi di:   
Questo forum è chiuso. Non puoi inserire, rispondere o modificare i Topics   Topic chiuso    Indice del forum :: Developers' Corner Tutti i fusi orari sono GMT + 1 ora
Vai a pagina 1, 2  Successivo
Pagina 1 di 2

 
Vai a:  
Non puoi inserire nuovi Topic in questo forum
Non puoi rispondere ai Topic in questo forum
Non puoi modificare i tuoi messaggi in questo forum
Non puoi cancellare i tuoi messaggi in questo forum
Non puoi votare nei sondaggi in questo forum




Powered by phpBB © 2001, 2002 phpBB Group
Charcoal2 Theme © Zarron Media

PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Generazione pagina: 0.25 Secondi

:: Charcoal2 phpbb2 style by zarron designs © :: PHP-Nuke theme by www.nukemods.com © ::