here i'm trying to make a program that when i press the keyboard "F6", it would auto. move the cursor to a position and click. I tested my program on desktop, it works. But when I go into a game and press F6, it doesn't seem to be working. Some people work, some people does not. I was thinking is there any like keypreview priority that I can do?
private async void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
if (IsKeyPushedDown(Keys.F6))
{
if (auth == 0)
{
MessageBox.Show("请先登录");
timer1.Start();
return;
}
SendKeys.Send("{ESC}");
//Original
if (rdbtnoriginal.Checked == true)
{
await Task.Delay(5000);
hack();
}
}
timer1.Start();
}
Here I use a timer tick, I got the code from online, so when I'm not focusing on the form and press F6 it will trigger the event. But some people go into the game and press F6 it doesn't work
Winforms relies on the window being focused for key messages to register in the application (if the window isn't focused, the IsKeyPushedDown won't register any keys as the window hasn't recieved the keypressed message in the background. you may want to use the input features from DXInput or OpenGL, or have a look at this http://www.codeproject.com/Articles/18890/NET-Hookless-Key-logger-Advanced-Keystroke-Mining. there are probably other libraries/pieces of code. Google is your friend, Key logging is probably your best search term.
Related
I would like to create a function like in Whatsapp for a WPF App with Win10 and with C#. I habe a normal button with some Text on it. As long as the button is pressed with hand touch or a stylus pen, the applikation should record and as soon as the button is untouched, it should stop the recording.
thats my code so far: I may add the I always youse the Preview-Versions of these Events
private void ButtonLiveDown(object sender, touchEventArgs e)
{
ButtonLiveOn();
}
private void ButtonLiveUp(object sender, TouchEventArgs e)
{
ButtonLiveOff();
}
private void ButtonLiveOn()
{
SetMicVolume(100);
isRecording = true;
}
private void ButtonLiveOff()
{
SetMicVolume(0);
isRecording = false;
}
for the recording, or better live announcement I use function in Windows systemsettings where you can say which microphone input schould be sent directly to the speaker
Now my Problem: I can start the speaking as soon as I press the button, but it doesn't matter if I hold the button or release him just directly after, The untouch event seems not to work, the Microphone is not set to 0. So I can't stop the live announcement. I want the function like in WhatsApp, the voice message is recording untill the button is released. What do I do wrong?
I'm trying to kill a game process by pressing F7. The app do work when the game is minimized and the form is on top. But when I'm playing the game (maximized) the app doesnt work. What can I do to solve this?
This is my code
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F7)
{
foreach (Process p in System.Diagnostics.Process.GetProcessesByName("processs"))
{
p.Kill();
}
}
}
When you press a key only the active window will get the message. If this weren't true then every running program would have to actively ignore keystrokes.
If you want to be able to intercept keys even when not the active window then you need a global keyboard hook. There are a few examples of this scattered around the web. One that looks promising at first glance is this article on CodeProject.
Well, so first of all I am pretty new to programming in Windows Form Application, so if I lack knowledge I hope you'll understand.
The program I am currently doing is a virtual piano in Windows Form Application. There are buttons on the screen, each button represent a piano "button", if one is clicked - it plays a sound. Now, what I wanted to know is if there is any way that I can program my piano into detecting a continuous click and play sound until the button is "unclicked". For example, if one keeps on clicking on the "G" chord button it will keep playing the sound until he stops clicking.
If I didn't provide any necessary information I would love to know. Thanks in advance to all the answers.
The thing you are looking for is "hold button event".
You could handle the MouseDown and MouseUp events, something like this:
private bool buttonDown;
private void btn1_MouseDown(object sender, MouseEventArgs e)
{
buttonDown = true;
int num = 0;
do
{
num++;
label1.Text = num.ToString();
Application.DoEvents();
} while (buttonDown);
}
private void btn1_MouseUp(object sender, MouseEventArgs e)
{
buttonDown = false;
}
This will starts executing the code when you click the button and keeps executing it until you release the button
You need to use mousedown event. When mouse will enter the button the you need to raise the button click event unit the mouseup event fire.
The following code is to test the LWin keyup function in C# when the form is active. It's working fine and now when the form is active I need only the function alone has to take place and whenever I click on Lwin button start menu should not open. How can I achieve this?
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.LWin)
{
MessageBox.Show("Function working!");
}
}
What have you tried?
Try setting e.Handled to True.
Try the same thing with the KeyPress event. And the KeyDown event.
If these options don't work (and I suspect they won't), you've exhausted the options available to you in managed Windows Forms. I can't immediately think of a solution using P/Invoke, but I think that's the avenue you'll have to explore.
I have C# app that monitors keystrokes via KeyDown and KeyPress events. Specifically, it watches for a VolumeMute keystroke (from a handheld device) to do some special processing. It works fine with one problem: Windows seems to intercept the VolumeMute keystroke and mutes the system volume (which I don't want to happen). I think Windows intercepts the keystroke before it is processed by my app because even when I signal the keystroke was handled (e.Handled = true), it mutes the system volume anyway. BTW, the same code works perfectly for other keystrokes I'm catching (ex Backspace, ect).
Is there a way to stop Windows from doing this volume mute?
System: WinXP SP3, .Net 4 Client Profile, Windows Forms app
Code snips
bool keyHandled = false;
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (keyHandled)
{
e.Handled = true;
}
}
// =====================================
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
keyHandled = false;
switch (e.KeyCode)
{
case Keys.VolumeMute:
DoSpecialProcessing();
keyHandled = true;
break;
default:
break;
}
e.Handled = keyHandled;
}
The button acts like a toggle, it will mute on the first press and "un-mute" on the next press. All you need is to simulate VolumeMute press again.
This answer explains how to do it.
Note: If you call this method from inside KeyDown handler then you probably need to use BeginInvoke or PostMessage to post a message to a message queue and return immediately in order to avoid race conditions.
Ok. I ended up using AutoHotKey to remap the VolumeMute to another key. Importantly, Windows never sees the VolumeMute keystroke before it gets remapped and doesn't mute the sound. So I can just start this AutoHotKey remap script when I need it. Beats messing with the Windows Registry. Thanks for the suggestions.