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

PressBackground not working #3

Closed
kosnkow opened this issue Sep 6, 2016 · 19 comments
Closed

PressBackground not working #3

kosnkow opened this issue Sep 6, 2016 · 19 comments

Comments

@kosnkow
Copy link

kosnkow commented Sep 6, 2016

I tried with visual studio 2015 (run as administrator), windows 10, sending keys in background application like notepad++ or wordpad or calculator and it doesn't work. nothing shows in these apps

@EasyAsABC123
Copy link
Owner

Make sure you are compiling your app as x86

Justin Schuhmann

On Sep 6, 2016, at 4:02 AM, kosnkow notifications@github.com wrote:

I tried with visual studio 2015, windows 10, sending keys in background application like notepad++ or wordpad or calculator and it doesn't work. nothing shows in these apps


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@kosnkow
Copy link
Author

kosnkow commented Sep 10, 2016

I am sure, anyway sending background doesn't work, program runs, but reciever in my case notepad++ doesn't recieve anything.

@EasyAsABC123
Copy link
Owner

The pid is likely wrong, I know when I used this I had to send it to a child process of the main app. Spy++ is your friend

On Sep 10, 2016, at 2:15 AM, kosnkow notifications@github.com wrote:

I am sure, anyway sending background doesn't work, program runs, but reciever in my case notepad++ doesn't recieve anything.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@TheAlmightyGuru
Copy link

I'm having a similar problem. Built as x86 in VS 2010. BackgroundKeyboardDemo works great at sending all the text to the richtextbox it creates, but it partially fails on some external programs.

In the BackgroundKeyboardDemo source, I commented out the "var procId = Process.GetCurrentProcess().MainWindowHandle;" line and added "var procId = (IntPtr) 0x010A076C;" which is the window handle of an open Cmd window (according to Spy++). This also works just fine. "hello world" is sent followed by an Enter which naturally results in an error, then the Cmd window receives the "sent one key at a time" text.

However, when I run the demo using the window handle of an open Notepad window, I get the "hello world" text from SendChatTextSend(), but it doesn't receive the Enter or the "sent one key at a time" text. Just to be thorough, I tried all three of the window handles of Notepad exposed in Spy++ (title bar, edit, and status bar). Only the Edit window receives text, but it only gets partial text. Anything you could suggest?

@EasyAsABC123
Copy link
Owner

It appears notepad doesn't accept VK_RETURN as a SendMessage, it does accept it in a PostMessage.

Meaning for some reason using:

            Messaging.SendChatTextPost(notepadTextbox, "hello world!!!");
            Messaging.SendChatTextPost(notepadTextbox, "test!!!");

this will work, partly. ! is being turned into a 1, and I think SendChatText presses enter twice, one time because the game opened a chat when Enter was pressed...then another after the text.

In notepad you don't actually need to send the keystrokes individually and can use WM_SETTEXT.

I should probably clean this library up so that it is a little cleaner, since a lot of what I just mentioned don't have easy fixes without changing the base library which means it is not as extensible as I would like..

@TheAlmightyGuru
Copy link

Looks like PostMessage() can handle Enter, but not shift (upper case letters appear as lower and symbols as numbers). I think I can hobble together a way to automate various programs by using SendMessage() for text and symbols, and then PostMessage() for special keys like enter and tab, but I'll keep an eye on this if you rework it!

@tobster-de
Copy link

tobster-de commented Dec 2, 2016

This code has some issues (unessecary recursions e.g.). The one you are referring to is the mismatch of the shift key codes. I tried to refactor it but got near a complete rewrite and it's even not working correctly yet. I finally gave up. (I'm about to use InputSimulator).

Nevermind: According to MSDN shift values are as follows:

[Serializable, Flags]
public enum ShiftType
{
     NONE = 0x0,
     SHIFT = 0x1,
     CTRL = 0x2,
     SHIFT_CTRL = SHIFT | CTRL,
     ALT = 0x4,
     SHIFT_ALT = ALT | SHIFT,
     CTRL_ALT = CTRL | ALT,
     SHIFT_CTRL_ALT = SHIFT | CTRL | ALT
}

In Messaging.cs ALT is mistaken with SHIFT. I hope this helps a bit.

@EasyAsABC123
Copy link
Owner

EasyAsABC123 commented Dec 2, 2016 via email

@EasyAsABC123
Copy link
Owner

updated codes

@IneedHelp
Copy link

Unfortunately

var key = new Key(Messaging.VKeys.KEY_1);            
var success = key.PressBackground(hWnd: windowHandle);

still doesn't work : (

Trying to send keys to notepad2 using a 64-bit application.

@EasyAsABC123
Copy link
Owner

EasyAsABC123 commented Sep 18, 2018 via email

@IneedHelp
Copy link

IneedHelp commented Sep 18, 2018

Yes, the hwnd is good because it works when used with PressForeground (although it only works if the window is not minimized, only if it's in the background or focused), but PressBackground has no effect (no matter what state the window is in: minimized, in the background or focused), yet it returns true.

@EasyAsABC123
Copy link
Owner

EasyAsABC123 commented Sep 18, 2018 via email

@IneedHelp
Copy link

So it's possible that it might not work at all? What other hwnd can I get for background than the window hwnd?

@EasyAsABC123
Copy link
Owner

EasyAsABC123 commented Sep 18, 2018 via email

@IneedHelp
Copy link

I understand, thank you for the help.

@IneedHelp
Copy link

IneedHelp commented Sep 21, 2018

One more question regarding PressBackground, is it known that application developed with https://electronjs.org/ like Discord and Spotify don't accept any messages when not focused?

Because I am trying it with Discord and Spotify and it doesn't when using PressBackground and this time I'm getting the correct window handles, there's just 2 of them:
image

However, PressBackground does work on them if the windows are in focus.

@EasyAsABC123
Copy link
Owner

EasyAsABC123 commented Sep 21, 2018 via email

@IneedHelp
Copy link

I understand. Thank you for the information.

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

5 participants