Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Shinigamae opened this issue Jan 6, 2016 · 9 comments
Closed

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

Shinigamae opened this issue Jan 6, 2016 · 9 comments

Comments

@Shinigamae
Copy link

I have created new project using:

  • IDE: Visual Studio 2015
  • .NET 4.0 as target framework
  • Windows Form application, no Administrative priviledge required
  • Sample application: BlueStacks 2.0

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
Copy link
Owner

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

@Shinigamae
Copy link
Author

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

@EasyAsABC123
Copy link
Owner

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
#2 (comment)
.

@Shinigamae
Copy link
Author

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
Copy link
Author

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

@EasyAsABC123
Copy link
Owner

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
#2 (comment)
.

@Shinigamae
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants