Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Machacaz

controlar aplicação através do c#

Recommended Posts

Machacaz

Saudações.

Estou a fazer uma aplicação para controlar o powerpoint (2007).

Neste momento consigo simular o "clique de rato" e aplicação avança um, dois slides.

Agora o que não estou a conseguir é simular as setas direccionais e as teclas "b" e "w".

Alguma ideia de como fazer?

Pela pesquisa que fiz, a coisa podia ser feita através do método sendkeys, mas dá-me erro e não estou a ver como resolver.

O meu código:

        public void DoMouseClick()
        {
            int X = Cursor.Position.X;
            int Y = Cursor.Position.Y;
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
        }

        public void nextKey()
        {
            SendKeys.SendWait("{DOWN}");
        }

        public void prevKey()
        {
            SendKeys.SendWait("{UP}");
        }

        public void screenColorWhite()
        {
            SendKeys.SendWait("{b}");
        }

        public void screenColorBlack()
        {
            SendKeys.Send("{w}");
        }

E o erro que obtenho:

System.InvalidOperationException was unhandled
Message="Queue empty."
Source="mscorlib"
StackTrace:
at System.Collections.Queue.Dequeue()
at System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents)
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.SendWait(String keys)
at pPoint.pEvents.nextKey() in C:\Documents and Settings\Machacaz\My Documents\Visual Studio 2008\Projects\dawnProject35\pPoint\pEvents.cs:line 32
at pPoint.pEvents.run() in C:\Documents and Settings\Machacaz\My Documents\Visual Studio 2008\Projects\dawnProject35\pPoint\pEvents.cs:line 58
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: 

Share this post


Link to post
Share on other sites
Machacaz

Ajuda alguém?

:wallbash:

class pEvents
    {
        [system.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
        public static extern void keybd_event(uint bVk, uint bScan, long dwFlags, long dwExtraInfo);

        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;
        private const uint Next = 0x28;


        public void DoMouseClick()
        {
            //Call the imported function with the cursor's current position
            int X = Cursor.Position.X;
            int Y = Cursor.Position.Y;
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
        }

        public void nextKey()
        {
            //uint xkey = 28;
            keybd_event(Next, 0x28, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
        }

Achei isto:

http://msdn.microsoft.com/en-us/library/ms646304%28VS.85%29.aspx

Mas ao tentar aplicar, como puderam ver, não consegui obter resultados  :/ continua a dar erro :/

Ajuda?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.