Siemka :)
Dzisiaj miałem troche więcej czasu to Ci napisalem ten sit :P
<Window x:Class="Klick.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Klick"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="pnlGrid" KeyDown="Grid_KeyDown">
<RichTextBox x:Name="textBox" TextChanged="RichTextBox_TextChanged"/>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Klick
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private bool? isEnable = false;
public MainWindow()
{
InitializeComponent();
pnlGrid.AddHandler(FrameworkElement.KeyDownEvent, new KeyEventHandler(Grid_KeyDown), true); // Łapie event ktory jest odpowiedzialny za przechwytywanie wciskanych przyciskow na klawiaturze
}
//EVENT KTORY PRZECHWYTUJE TO CO WPISUJESZ NA KLAWIATURZE
private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if(isEnable == true)
{
System.IO.StreamWriter file = new System.IO.StreamWriter("test.txt");
string text = new TextRange(textBox.Document.ContentStart, textBox.Document.ContentEnd).Text;
file.WriteLine(text);
file.Close();
}
}
//Skrypt uruchami sie dopiero po wcisnieciu SHIFT + F1 a wylaczy sie po wcisnieciu SHIFT + F2
private void Grid_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftShift) && Keyboard.IsKeyDown(Key.F1) || Keyboard.IsKeyDown(Key.RightShift) && Keyboard.IsKeyDown(Key.F1))
{
isEnable = true;
}
else if (Keyboard.IsKeyDown(Key.LeftShift) && Keyboard.IsKeyDown(Key.F2) || Keyboard.IsKeyDown(Key.RightShift) && Keyboard.IsKeyDown(Key.F2))
{
isEnable = false;
}
}
}
}
Ogolnie zamysł jest banalnie prosty, wszystkie zmiany są zapisywanie do pliku text.txt.
Pozdro :)
PS. Mozna to napisac wydajniej, ale to juz twoja brocha, pokazałem Ci droge :). Ale jak widze jak ty eventy tworzysz to najpierw sie poszkol ich tworzeniu i wywolywaniu. public MainWindow() <- konstruktor tutaj sie eventow nie dodaje, chyba ze sie tworzy Handler jak ja.