Game Killer doesnt work in game c# - c#

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.

Related

Creating something like whatsapp voice mail button. Release button don't work

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?

C# - keydown event when form is not active

Hi I am making an application sort of like a mouse macro where when you press F it will move the mouses position between two spots, everything works the only issue I am running into is that I want this to work in the background as in when the form isnt pulled up on my screen. How can I do this? If anyone can help me that would be awesome.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F)
{
PointConverter pc = new PointConverter();
Point pt = new Point();
pt = (Point)pc.ConvertFromString("60, 700");
Cursor.Position = pt;
System.Threading.Thread.Sleep(5000);
pt = (Point)pc.ConvertFromString("600, 700");
Cursor.Position = pt;
}
The events only apply to the form while its active. You cannot use events in a form in the background. Instead use the GetKeyState function.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).aspx
Take a look at virtual key codes too. I made an application that listens for key presses in the background once. I had to use GetKeyState in a loop that checked every virtual key code to see if it has been pressed. But sounds like for your application you just need to check for the hot keys you want to listen out for.
You'll need to run a thread in the background for your loop or use a timer maybe.
-Edit-
Here's some more code to implement the GetKeyState function.
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern byte GetKeyState(int nVirtKey);

How can I make my Form visible/invisible by pressing insert?

I'm trying to find out how to making my form invisible when I press insert and when I press insert again it makes the form visible. I try to find out how, but no one seems to have what I am looking for.
A simple example how you can manipulate Form's visibility by handling the Insert key down:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
// Don't forget to enable Form.KeyPreview in order to receive key down events
if (e.KeyCode == Keys.Insert)
{
Visible = false;
}
}
}
You can set Visible back to true to make it visible. However, you will not be able to do this, because Form became invisible and doesn't receive key down events anymore. In this case you can try to set the global hotkey using, for example, the GlobalHotKey library described here. Note also, that it doesn't make sense to set a single key (e.g. Insert) as global hotkey as in most cases system or another application will capture it.
You can do this:
private void InfoForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Insert) Opacity = Opacity == 0 ? 1 : 0;
}
For this to work you need to turn on the Form's KeyPreview property!
But turning visiblity back on (or to be precise turning off opacity) will only work if no other program has received focus in the meantime.
If that might happen you need to set a global keyboard hook; make sure to pass the Insert key back on or else many other programms will no longer work right.. All in all I would not recommend it..
I'm not sure when the whole idea might make sense. One answer could be to show or hide a popup data window that is only meant to show some additional information popping up from a base data window.
In that case you could simply close the window whenever it gets deactivated:
private void InfoForm_Deactivate(object sender, EventArgs e)
{
this.Close();
}

C# set winform key preview highest priority

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.

how to minimize window to maximize window using shortcut key in window application using c#?

how to minimize window to maximize window using shortcut key in window application using c# ?
Set Form Propertie "KeyPreview" = true.
Then use this code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.B)
{
WindowState = FormWindowState.Minimized;
}
}
Looking at your accept rate, I will give you the steps:
Add a KeyDown event handler on to the form you want minimized/maximized.
Add code to check for the key combination you want
Use Form.WindowState to set the state you require.
As a sidenote, please start accepting answers. You can do it by clicking the "tick" next to an answer that helped you solve your problem.
thanxs man its working and if we can change our state with this key follow this code..
if (e.Key == Key.F11)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
else
{
this.WindowState = WindowState.Maximized;
}
}
Werewolve mentioned correct link!
When application is minimized it will not receive any keyboard input. Otherwise applications would not who was the keyboard target.
If you want your application to receive signal when specific keys combination where pressed you should register this combination by calling RegisterHotKey Windows API function.
Your form showing/maximising action could be invoked by this signal/

Categories