VirtualKey C# Windows Store App - c#

I'm writing a Windows Store App for Windows 8. I have two buttons on the screen that I'd like to toggle with the space bar: when the start button in pressed I disable it and enable the stop button, and visa versa.
I can start and stop using the spacebar, but I have a problem after I click any button with the mouse: then the focus is on a different button, which I then accidentally press with the space bar.
I want the focus to be on the stop button after I clicked the start button, so I can press the stop button with the space bar. How should I do that?
public void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Space)
{
if(!isPlaying)
{
StartButton_Click(sender, null);
}
else
{
StopButton_Click(sender, null);
}
}
}
Regards

In StartButton_Click call
StopButton.Focus(Focus.Programmatic);

Related

KeyDown Event, triggered when AutoCompleteBox drop-down is opened

In AutoCompleteBox, when drop-down is opened and key is pressed (for example Enter) control's KeyDown event is not arroused, and this makes to press Enter two times. I'm trying to make small dialog box, that doesn't oblige user to press keyboard buttons lots of times, but which closes with result when user has found his variant and presses Enter only one time. How to catch this event?
AXAML:
<AutoCompleteBox
FilterMode="Contains"
KeyDown="InputBox_KeyDown"/>
C#:
private async void InputBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
// Getting form result
Close();
}
}

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?

Prevent Windows firing events during long touch of a button

WinForms application.
User touches a button (touchscreen) that causes authentication and the screen (A) is changed to another screen (B). If user continues to hold the finger on the screen (just for a second) the screen B has a button that overlaps with the button on screen (A) and the button on screen B inadvertently gets a touch and invokes an action that is not supposed to happen...
How do I do to prevent this from happening?
That is weird behavior. I do not have a touch device to test this but in a regular scenario the click only triggers when the button is pressed and then released while the button is still in focus. If you press the button and do not release, the click event will not fire.
Anyhow perhaps what you can do is only show screen B when the button has been pressed and then it has lost focus. Like this:
private bool buttonIsClicked = false;
private void button1_Click(object sender, EventArgs e)
{
this.buttonIsClicked = true;
}
private void button1_Leave(object sender, EventArgs e)
{
if (this.buttonIsClicked)
{
this.buttonIsClicked = !this.buttonIsClicked;
// show screen B
}
}
Please use a variable like I have used buttonIsClicked so the code in Leave event handler is not executed every time the button loses focus even if it is not clicked.

C# Windows Form Application Long Button Click

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.

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.

Categories