Sendkeys infinite loop

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Sendkeys infinite loop



I'm using RawInput methods to intercept global keyboard keystrokes then send a string to the focused foregroundwindow, my problem is when i use sendkeys.send() i'm getting an infinite loop (the event is triggered each time)


sendkeys.send()



i've tried to delete the event then add it but didn't work, i found on some topics that the problem appears because the place where i sent the string still focused but i need it to still focused, e.g. of what i'm doing :



UPDATED


public static bool Keypressed = false;
private void OnKeyPressed(object sender, RawInputEventArg e)
{
if (Keypressed)Keypressed=false;return;

if (cpt == 0)
{
cpt++;
Console.WriteLine(e.KeyPressEvent.Name);
//Check the Device name first !!!!
//if(e.KeyPressEvent.Name.Contains(Settings.Default.DeviceName) || Settings.Default.DeviceName.Contains(e.KeyPressEvent.Name))
String ActiveProcess = ActiveApp.getActiveProccess();

switch (ActiveProcess)
API.getChromeUrl().Contains("messenger"))


SendKeys.Send("1");
//Clipboard.SetText(""+Previous);
Console.WriteLine(API.getChromeUrl());
Keypressed = true;

// String Previous = Clipboard.GetText();
// Clipboard.SetText(FBEmo.numpad0);




break;
case "mozzila":
break;
case "Skype":
break;
case "Viber":
break;



Console.WriteLine(ActiveProcess);





If I'm following, you are hooking keypress events, and when there's a keypress, you are simulating a keyptess, your hook is catching it, and so on. Have you considered having a flag (say "bool myKeypress") that you set right before you sendKeys (and clearing right afterwards). If your hook gets called while that flag is set, you just ignore it.
– Flydog57
Aug 11 at 22:08





@Flydog57 yes, even with a flag the event will always be active, so when i turn the flag true it resumes
– DzNiT0
Aug 11 at 22:32





I don't see anything that's flag-like in your code
– Flydog57
Aug 11 at 22:34





@Flydog57 see the update
– DzNiT0
Aug 11 at 22:39





its like if the event is always in some queue and every time starts, when i reopen the app window it stops when i focus on the messenger field it comes back
– DzNiT0
Aug 11 at 22:43




1 Answer
1



it works fine by using InputSimulator instead of Sendkeys.Send().


InputSimulator cmd = new InputSimulator();

if (e.KeyPressEvent.KeyPressState.Equals("BREAK"))
{
cpt = 0;
Console.WriteLine(e.KeyPressEvent.Name);
//Check the Device name first !!!!
//if(e.KeyPressEvent.Name.Contains(Settings.Default.DeviceName) || Settings.Default.DeviceName.Contains(e.KeyPressEvent.Name))
String ActiveProcess = ActiveApp.getActiveProccess();

switch (ActiveProcess)
{
case "chrome":
if(API.getChromeUrl().Contains("facebook") || API.getChromeUrl().Contains("messenger"))
{

switch (e.KeyPressEvent.VKeyName)
{
case "NUMPAD0":
cmd.Keyboard.TextEntry(FBEmo.numpad0);
break;






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS