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
[FeatureRequest] Sanderling.KeyboardPress(VirtualKeyCode Key) brings window to front #1
Comments
Yes, that would be nice. I am interested to see how this could be implemented.
The same way as in other .NET applications. using System.Runtime.InteropServices;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool MessageBeep(uint uType);
MessageBeep(0); |
i have succeeded with: const int WM_KEYDOWN = 0x100; [DllImport("User32.dll")] [DllImport("user32.dll")] int window = FindWindow("triuiScreen", null); void key(WindowsInput.Native.VirtualKeyCode keycode) //and finally also, can you show me an example of how can I use System.Speech.Synthesis.SpeechSynthesizer class? i would like to be announced of local chat changes ;) |
I understand this covers the case of simulating a single (not combined with others) keyboard key press. Would you benefit from an additional |
it would be nice to leave separate keyUP and keyDOWN mechanics for users to manage key modifiers. maybe someone needs holding a key for a long time. key(VirtualKeyCode.SPACE); //focus on overview key(VirtualKeyCode.VK_D); //warp|dock of course, this needs to sort overview by icon. yellow one will always be on top. |
… messages to window for key down and key up.
I made the changes required to support the mentioned uses. These are the signatures to use the key methods: bool WindowPostMessageKeyDown(VirtualKeyCode key, IntPtr lParam = default(IntPtr));
bool WindowPostMessageKeyUp(VirtualKeyCode key, IntPtr lParam = default(IntPtr));
I added a reference to It can be used like this: using System.Speech.Synthesis;
var synth = new SpeechSynthesizer();
synth.Speak("Sanderling at your service."); |
everything works perfectly. thank you very much! now i'm trying to simulate mouse clicks, but it seems the game has some kind of protection against this, so clicks are sent only to the coordinates of cursor on screen, no matter what coordinates are sent. I tried using SendMessage and PostMessage. maybe you will succeed with implementing this. it would be very nice to click all controls without losing focus of current window. const int WM_LBUTTONDOWN = 0x201; [DllImport("user32.dll")] [DllImport("User32.dll")] int window = FindWindow("triuiScreen", null); PostMessage((IntPtr)window, WM_KEYDOWN, (IntPtr)WM_LBUTTONDOWN, (IntPtr)(y_coord << 16) | x_coord)); SendMessage(window, WM_KEYDOWN, WM_LBUTTONDOWN, (y_coord << 16) | x_coord ); |
This is weird, but |
I would need to know what assumptions you used in order to understand how you arrived at these conclusions
How did you arrive at this conclusion?
How did you arrive at this conclusion?
Why do you expect it to spam? |
as i understand: but when i use these two lines, and my cursor is focused in chat, i see two letters D typed instead of one. if i try to use only pressing a button without a release (KeyDown without KeyUp), i expect it to become held down and to spam this letter if chat is focused. |
I see. This is not the case. These methods just call the WinAPI function 'PostMessage' and return its return value (The implementation can be seen at Sanderling/src/Sanderling/Sanderling/Script/ToScriptExtension.cs Lines 104 to 111 in c487043
The reason the text 'KeyDown' and 'KeyUp' are contained within the method names is that those are also used in the documentation from microsoft which describes the messages which are being posted by these methods (see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx). For example, a windows application can use the GetAsyncKeyState function to get information about the state of a key. So far, I don't see that the WM_KEYDOWN and WM_KEYUP messages affect the return value of this function as you expect. |
as for sending a mouse click. i failed multiple times trying to send a click to inactive game window. the closest answer i found was at https://autohotkey.com/board/topic/96814-using-postsendmessage-to-send-clicks-to-game-window/ but even this fails for me. clicks are only sent in current mouse position only if mouse cursor is within game client window. maybe you can spend a little time to investigate this? it would be very nice. tell me if i can somehow help. |
At the moment it seems the best option is to contain both applications in an VMWare instance or a windows remote desktop session. |
As title says, Sanderling.KeyboardPress(VirtualKeyCode Key) brings window to front. It would be very nice if this will send keystrokes to client window that is in background without focusing on it. Same with mouse.
Or maybe I can do this via WinAPI, but how can I use WinAPI in Sanderling?
The text was updated successfully, but these errors were encountered: