EasyAsABC123 / Keyboard

Background/Foreground Keyboard and Mouse input handler
102 stars 43 forks source link

Presskey doesn't work when adding to new project as library #2

Closed Shinigamae closed 8 years ago

Shinigamae commented 8 years ago

I have created new project using:

The purpose of application is to allow user to send a list of keys at set interval to an active (PressForeground) or background (PressBackground) application. I have added the Keyboard project to my project. Configured it to build for Any CPU and target .NET 4.0.

I tried to apply PressForeground function first but it doesn't send any key to application. It can call BlueStacks and bring the process to foreground but no key is sent there.

My code example: image

Regards, Khanh Nguyen

EasyAsABC123 commented 8 years ago

@Shinigamae is there an app I can send keystrokes to as an example for you?

Shinigamae commented 8 years ago

Sorry, I don't understand your question. Do you mean my application or the application I want to send keystrokes to?

EasyAsABC123 commented 8 years ago

the application you want to send the keystokes and mouse events to

On Wed, Jan 6, 2016 at 10:46 PM, Khanh Nguyen notifications@github.com wrote:

Sorry, I don't understand your question. Do you mean my application or the application I want to send keystrokes to?

— Reply to this email directly or view it on GitHub https://github.com/EasyAsABC123/Keyboard/issues/2#issuecomment-169540765 .

Shinigamae commented 8 years ago

It is BlueStacks app player which is used to emulate Android on Windows. You can download it at http://filehippo.com/download_bluestacks_app_player/ (300 MB+)

It has a feature to map a keystroke to a tap on its app screen.

Shinigamae commented 8 years ago

If you ever want to see my project, I can provide it. Just a small keypress app to use with BlueStacks. Thanks.

EasyAsABC123 commented 8 years ago

yeah if you don't mind just email it to me, i can sign a NDA if i need to for you. this allows me to help you more accurately than simply trying to mess with bluestacks since i don't have any experience with that. importantly i'd re-write this keyboard dll to be injection based in the

On Thu, Jan 7, 2016 at 11:54 AM, Khanh Nguyen notifications@github.com wrote:

If you ever want to see my project, I can provide it. Just a small keypress app to use with BlueStacks. Thanks.

— Reply to this email directly or view it on GitHub https://github.com/EasyAsABC123/Keyboard/issues/2#issuecomment-169726826 .

Shinigamae commented 8 years ago

I would love to see the DLL to be improved further than it is currently. https://drive.google.com/file/d/0B0Js4SLbvtXyY19nUS1DczZ6Um8/view?usp=sharing You may have to add your project into the solution of just use the built DLL file there. Hope it can help.

EasyAsABC123 commented 8 years ago

So I changed some of your code in Main.cs

        private void timerMain_Tick(object sender, EventArgs e)
        {
            try
            {
                counter++;
                if (chkShutdown.Checked)
                {
                    countdown--;
                    lblCountdown.Text = String.Format("({0} seconds remaining)", countdown);
                    if (countdown == 0) ExecuteShutdown(cbShutdownOptions.SelectedValue.ToString());
                }

                if (counter > list.Max(c => c.Value)) counter = 1;
                foreach (var l in list.Where(c => counter % c.Value == 0))
                {
                    var key = new Keyboard.Key(l.Key[0]);

                    if (chkBackground.Checked)
                        key.PressBackground(process.MainWindowHandle);
                    else
                        key.PressForeground(process.MainWindowHandle);
                }
            }
            catch (Exception ex)
            {
                Stop();
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

I also just added a Demo for background keypresses...basically this is just making use of the Key object in this library...it works 100%, the background keypresses require the actual hWnd to the Textbox you want text to go in...this might not always be the MainWindowHandle. The easiest way to find out what this is, is to use Spy++ it is built into Visual Studio > Tools > Spy++.

Next you need to make your app Build as a x86 app, since x64 background keypresses are next to impossible.

Shinigamae commented 8 years ago

Thank for your help, I would try it then. Cheers!