changes
changes
Controls;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using System;
using MsBox.Avalonia;
using System.Collections.Generic;
using WindowsInput;
using WindowsInput.Native;
using Avalonia.Controls.Notifications;
using Avalonia.Threading;
using Avalonia.Media.Imaging;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using Avalonia.Media.Immutable;
using Avalonia.Input;
using Avalonia.Remote.Protocol.Input;
using System.Linq;
using Avalonia;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
#if WINDOWS
using WindowsInput;
using WindowsInput.Native;
#endif
namespace MHZ_ATTS1
{
public partial class MainWindow : Window
{
// Region: KMCODE-1
// Total number of tabs/windows (will be selected by the user from combo)
private int totalTabs;
// Timer object
private System.Timers.Timer timer = new System.Timers.Timer();
// End Region
string BaseDirectory;
string projectDirectory;
string resourcesPath;
string imagePath;
string imagePath_;
string imagePath2;
string textFilePath;
#if WINDOWS
private InputSimulator inputSimulator = new InputSimulator();
#endif
public MainWindow()
{
InitializeComponent();
singleKeyTimer = new System.Timers.Timer();
combinedKeyTimer = new System.Timers.Timer();
NoOfTabsTimer = new System.Timers.Timer();
RandomTabsTimer = new System.Timers.Timer();
ActivateTimer = new System.Timers.Timer();
cursorTimer = new System.Timers.Timer();
singleKeyTimer.Enabled = false;
combinedKeyTimer.Enabled = false;
NoOfTabsTimer.Enabled = false;
RandomTabsTimer.Enabled = false;
ActivateTimer.Enabled = false;
cursorTimer = new System.Timers.Timer();
//singleKeyTimer.Elapsed += SingleKeyTimer_Elapsed;
combinedKeyTimer.Elapsed += CombinedKeyTimer_Elapsed;
NoOfTabsTimer.Elapsed += NoOfTabsTimer_Elapsed;
RandomTabsTimer.Elapsed += RandomTabsTimer_Elapsed;
ActivateTimer.Elapsed += ActivateTimer_Elapsed;
cursorTimer.Elapsed += CursorTimer_Elapsed;
}
#if WINDOWS
// Windows - Use InputSimulator
inputSimulator.Keyboard.KeyPress((VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode),
keyToPress.Replace("_", "").ToUpper()));
#else
//Cross - platform shell - based key simulation
if (OperatingSystem.IsWindows())
{
// Use InputSimulator for windows
if (keyToPress.Equals("{SCROLLLOCK}",
StringComparison.OrdinalIgnoreCase))
{
// Simulate Scroll Lock key press
inputSimulator.Keyboard.KeyPress(VirtualKeyCode.SCROLL);
}
}
else if (OperatingSystem.IsLinux())
{
// Use xdotool for Linux
Process.Start("/bin/bash", "-c \"xdotool key " + keyToPress +
"\"");
}
else if (OperatingSystem.IsMacOS())
{
// Use AppleScript for macOS
Process.Start("/bin/bash", "-c \"osascript -e 'tell
application \\\"System Events\\\" to keystroke \"" + keyToPress + "\"'\"");
}
#endif
Dispatcher.UIThread.InvokeAsync(() =>
{
// Logic for combined key timer
if (btnkey1.Background == Brushes.LightGreen)
{
SimulateKeyPress("Scroll Lock");
}
if (btnkey2.Background == Brushes.LightGreen)
{
SimulateKeyPress("Scroll Lock");
}
});
}
private void MenuItem_Click(object? sender,
Avalonia.Interactivity.RoutedEventArgs e)
{
About about = new About();
about.Show();
}
}
}
getAllFiles();
createTrayIcon();
keyList1.Clear();
keyList1.AddRange(FuncAddIntervals());
comInterval.ItemsSource = keyList1;
comSingleInterval.ItemsSource = keyList1;
keyList2.Clear();
keyList2.AddRange(FuncAddKeys());
comSingleKeys.ItemsSource = keyList2;
keyList3.Clear();
keyList3.AddRange(FuncAddTabsNo());
comTabs.ItemsSource = keyList3;
keyList4.Clear();
keyList4.AddRange(FuncAddTabsInterval());
comInterval2.ItemsSource = keyList4;
btnSingleStart.IsEnabled = false;
comSingleInterval.IsEnabled = false;
combinedKeyTimer.Enabled = false;
//NotifyIcon.Visible = true;
//NotifyIcon.ContextMenuStrip = notifi_menu;
hotkey.Register((int)HotKeyRegistryClass.Modifiers.MOD_CTRL,
Avalonia.Input.Key.F3);
hotkey.Register((int)HotKeyRegistryClass.Modifiers.MOD_CTRL,
Avalonia.Input.Key.F4);
hotkey.Register((int)HotKeyRegistryClass.Modifiers.MOD_CTRL,
Avalonia.Input.Key.F5);
hotkey.Register((int)HotKeyRegistryClass.Modifiers.MOD_CTRL,
Avalonia.Input.Key.F6);
hotkey.Register((int)HotKeyRegistryClass.Modifiers.MOD_CTRL,
Avalonia.Input.Key.F7);
hotkey.Register((int)HotKeyRegistryClass.Modifiers.MOD_CTRL,
Avalonia.Input.Key.F8);
hotkey.Register((int)HotKeyRegistryClass.Modifiers.MOD_CTRL,
Avalonia.Input.Key.F9);
// Region: KMCODE-2
// Attach the event handler for the timer
timer.Elapsed += OnTimedEvent;
// End Region
targetTabIndex = shuffledTabs[shuffledIndex];
shuffledIndex++;
}
if (togglescreenbutton.IsChecked == true)
{
// Initialize the available windows (1 to
selectedNumberOfScreens)
availableWindows = Enumerable.Range(1,
int.Parse(comTabs.SelectedItem.ToString())).ToList();
//RandomUpDownKeyPresses();
int x = 0;
private void RandomUpDownKeyPresses()
{
var sim = new InputSimulator();
int upPresses = 0;
int downPresses = 0;
if (x == 0)
{
for (int i = 0; i < 30; i++)
{
sim.Keyboard.KeyPress(VirtualKeyCode.UP);
Thread.Sleep(100); // Delay of 100ms
}
x = 1;
}
else if(x==1)
{
for (int i = 0; i < 30; i++)
{
sim.Keyboard.KeyPress(VirtualKeyCode.DOWN);
Thread.Sleep(100); // Delay of 100ms
}
x = 0;
}
currentTabIndex = targetTabIndex;
currentTabIndex = targetTabIndex;
}
currentTabIndex = targetTabIndex;
//currentTabIndex = targetTabIndex;
//currentTabIndex = targetTabIndex;
if (comInterval.SelectedItem == null ||
comInterval.SelectedItem.Equals("0"))
{
// Replace MessageBox with a custom dialog in Avalonia
var messageBox = MessageBoxManager.GetMessageBoxStandard("Error",
"Please select a valid interval.");
messageBox.ShowWindowDialogAsync(this);
}
else if (btnKeyComStart.Content.ToString() == "Stop" &&
(btnkey1.Background == Brushes.LightGreen || btnkey2.Background ==
Brushes.LightGreen))
{
btnKeyComStart.Content = "Start";
combinedKeyTimer.Enabled = false;
comInterval.IsEnabled = false;
btnkey1.Background = Brushes.WhiteSmoke;
btnkey2.Background = Brushes.WhiteSmoke;
btnkey1.Foreground = Brushes.SkyBlue;
btnkey2.Foreground = Brushes.SkyBlue;
comInterval.SelectedIndex = -1;
btnKeyComStart.IsEnabled = false;
btnKeyComStop.IsEnabled = false;
btnkey1.IsEnabled = true;
btnkey2.IsEnabled = true;
}
else
{
btnKeyComStart.Content = "Stop";
if(btnkey1.Background == Brushes.LightGreen && btnkey2.Background
== Brushes.LightGreen)
{
btnkey1.IsEnabled = false;
btnkey2.IsEnabled = false;
}
else
{
btnkey1.IsEnabled = false;
btnkey2.IsEnabled = false;
combinedKeyTimer.Interval =
FuncInterval(double.Parse(comInterval.SelectedItem.ToString()));
combinedKeyTimer.Enabled = true;
btnKeyComStop.IsEnabled = true;
comInterval.IsEnabled = false;
singleKeyTimer.Enabled = false;
btnSingleStart.IsEnabled = true;
comSingleKeys.IsEnabled = true;
btnSingleStop.IsEnabled = false;
}
}
if (comSecondKey.Content.ToString() == "-----Numbers-----")
{
comInterval.IsEnabled = false;
btnKeyComStart.IsEnabled = false;
}
else if (comSecondKey.Content.ToString() == "-----Alphabets-----")
{
comInterval.IsEnabled = false;
btnKeyComStart.IsEnabled = false;
}
else if (comSecondKey.Content.ToString() == "-----Function Keys-----")
{
comInterval.IsEnabled = false;
btnKeyComStart.IsEnabled = false;
}
else if (comSecondKey.Content.ToString() == "-----Special Keys-----")
{
comInterval.IsEnabled = false;
btnKeyComStart.IsEnabled = false;
}
else
{
comInterval.IsEnabled = true;
}
}
// Lock Keys
if (userSelectedKey == "Num Lock")
varKey = "{NUMLOCK}";
else if (userSelectedKey == "Caps Lock")
varKey = "{CAPSLOCK}";
else if (userSelectedKey == "Scroll Lock")
varKey = "{SCROLLLOCK}";
else if (userSelectedKey == "TAB")
varKey = "{TAB}";
else if (userSelectedKey == "Return/Enter")
varKey = "{ENTER}";
else if (userSelectedKey == "Spacebar")
varKey = " ";
// Control, Alt, and Shift
else if (userSelectedKey == "Ctrl")
varKey = "^";
else if (userSelectedKey == "Alt")
varKey = "%";
else if (userSelectedKey == "Shift")
varKey = "+";
else if (userSelectedKey == "ESC")
varKey = "{ESC}";
// if (userSelectedKey == "Windows")
// varKey = "{WINDOWS}";
else if (userSelectedKey == "Delete")
varKey = "{DELETE}";
else if (userSelectedKey == "Backspace")
varKey = "{BKSP}";
// Arrow Keys
else if (userSelectedKey == "Down Arrow")
varKey = "{DOWN}";
else if (userSelectedKey == "Up Arrow")
varKey = "{UP}";
else if (userSelectedKey == "Left Arrow")
varKey = "{LEFT}";
else if (userSelectedKey == "Right Arrow")
varKey = "{RIGHT}";
// Home, End, Insert
else if (userSelectedKey == "Home")
varKey = "{HOME}";
else if (userSelectedKey == "End")
varKey = "{END}";
else if (userSelectedKey == "Insert")
varKey = "{INSERT}";
// Page Up and Page Down
else if (userSelectedKey == "Page Up")
varKey = "{PGUP}";
else if (userSelectedKey == "Page Down")
varKey = "{PGDN}";
else if (userSelectedKey == "Print Screen")
varKey = "{PRTSC}";
return varKey;
}
// // Lock Keys
// if (userSelectedKey == "Num Lock")
// {
// varKey = "{NUMLOCK}";
// }
// else if (userSelectedKey == "Caps Lock")
// {
// varKey = "{CAPSLOCK}";
// }
// else if (userSelectedKey == "Scroll Lock")
// {
// varKey = "{SCROLLLOCK}";
// }
// else if (userSelectedKey == "TAB")
// {
// varKey = "{TAB}";
// }
// else if (userSelectedKey == "Return/Enter")
// {
// varKey = "{ENTER}";
// }
// else if (userSelectedKey == "Spacebar")
// {
// varKey = " ";
// }
// // Control, Alt and Shift
// else if (userSelectedKey == "Ctrl")
// {
// varKey = "^";
// }
// else if (userSelectedKey == "Alt")
// {
// varKey = "%";
// }
// else if (userSelectedKey == "Shift")
// {
// varKey = "+";
// }
// else if (userSelectedKey == "ESC")
// {
// varKey = "{ESC}";
// }
// else if (userSelectedKey == "Delete")
// {
// varKey = "{DELETE}";
// }
// else if (userSelectedKey == "Backspace")
// {
// varKey = "{BKSP}";
// }
// // Arrow Keys
// else if (userSelectedKey == "Down Arrow")
// {
// varKey = "{DOWN}";
// }
// else if (userSelectedKey == "Up Arrow")
// {
// varKey = "{UP}";
// }
// else if (userSelectedKey == "Left Arrow")
// {
// varKey = "{LEFT}";
// }
// else if (userSelectedKey == "Right Arrow")
// {
// varKey = "{RIGHT}";
// }
// // Home End Insert
// else if (userSelectedKey == "Home")
// {
// varKey = "{HOME}";
// }
// else if (userSelectedKey == "End")
// {
// varKey = "{END}";
// }
// else if (userSelectedKey == "Insert")
// {
// varKey = "{INSERT}";
// }
// // Page up and page down
// else if (userSelectedKey == "Page Up")
// {
// varKey = "{PGUP}";
// }
// else if (userSelectedKey == "Page Down")
// {
// varKey = "{PGDN}";
// }
// else if (userSelectedKey == "Print Screen")
// {
// varKey = "{PRTSC}";
// }
// return varKey;
//}
if (btnkey1.Background == Brushes.LightGreen)
{
// If the background color is green, change it to transparent
btnkey1.Background = Brushes.WhiteSmoke;
btnkey1.Foreground = Brushes.SkyBlue;
}
else
{
// Otherwise, change it to green
btnkey1.Background = Brushes.LightGreen;
btnkey1.Foreground = Brushes.White;
}
// Enable the interval combo box again (redundant, but included for
completeness)
comInterval.IsEnabled = true;
}
}
private void Button_Click_7(object? sender,
Avalonia.Interactivity.RoutedEventArgs e)
{
comInterval.IsEnabled = true;
btnKeyComStart.IsEnabled = true;
if (btnkey2.Background == Brushes.LightGreen)
{
// If the background color is green, change it to transparent
btnkey2.Background = Brushes.WhiteSmoke;
btnkey2.Foreground = Brushes.SkyBlue;
}
else
{
// Otherwise, change it to green
btnkey2.Background = Brushes.LightGreen;
btnkey2.Foreground = Brushes.White;
}
// Enable the interval combo box (redundant, but included for clarity)
comInterval.IsEnabled = true;
Dispatcher.UIThread.InvokeAsync(() =>
{
if (isAltPressed == true)
{
txtStatus.Text += "Alt Pressed-\n";
isAltPressed = false;
NoOfTabsTimer.Stop();
}
});
}
#endregion
private void RandomTabsTimer_Elapsed(object? sender,
System.Timers.ElapsedEventArgs e)
{
Dispatcher.UIThread.InvokeAsync(() =>
{
txtStatus.Text += "TAB Pressed-\n";
if (isAltPressed && isTabPressed)
{
NoOfTabsTimer.Stop();
RandomTabsTimer.Stop();
Random ran = new Random();
comInterval2.SelectedItem = ran.Next(2, 10).ToString();
isAltPressed = false;
if (comFirstKey.IsVisible == false)
{
comFirstKey.IsVisible = true;
// Key 2 Press 3 times
Button_Click_7(null, null);
Button_Click_7(null, null);
Button_Click_7(null, null);
}
else
{
comFirstKey.IsVisible = false;
comSecondKey.IsVisible = true;
// Key 1 Press 4 times
Button_Click_6(null, null);
Button_Click_6(null, null);
Button_Click_6(null, null);
Button_Click_6(null, null);
btnActivate.IsEnabled = true;
}
}
});
}
trayIcon.IsVisible = false;
Environment.Exit(0);
}
// Add a separator
var separator1 = new NativeMenuItemSeparator();
var separator2 = new NativeMenuItemSeparator();
trayIcon.Menu = menu;
trayIcon.IsVisible = true;
if (toggleSwitch.IsChecked == true)
{
TogglePanelPro.IsEnabled = true;
btnActivate.Content = "Activate";
comInterval2.IsEnabled = true;
comTabs.IsEnabled = true;
toggletabbutton.IsEnabled = true;
togglescreenbutton.IsEnabled = true;
toggleCursor.IsEnabled = true;
}
else if (toggleSwitch.IsChecked == false)
{
TogglePanelPro.IsEnabled = false;
btnActivate.Content = "Activate";
toggletabbutton.IsEnabled = false;
togglescreenbutton.IsEnabled = false;
toggleCursor.IsEnabled = false;
toggletabbutton.IsChecked = false;
togglescreenbutton.IsChecked = false;
toggleCursor.IsChecked = false;
toggleCursor.Content = "Enable Cursor Movement";
if (comInterval2.SelectedIndex == -1)
{
var messageBox =
MessageBoxManager.GetMessageBoxStandard("Error", "Please select an interval");
messageBox.ShowWindowDialogAsync(this);
return;
}
timer.Interval = intervalTime;
timer.AutoReset = true;
timer.Elapsed += OnTimedEvent;
timer.Start();
comTabs.SelectedIndex = -1;
comInterval2.SelectedIndex = -1;
}
toggletabbutton.IsChecked = false;
lbl_selectNoTabs.Content = "Select No. of Screen";
}
}
int x = rand.Next(screenWidth);
int y = rand.Next(screenHeight);
// Windows APIs
[DllImport("user32.dll")]
private static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
private static extern void mouse_event(uint dwFlags, int dx, int dy, uint
dwData, UIntPtr dwExtraInfo);
// macOS APIs
private static void MacMoveCursor(int x, int y)
{
// Use CoreGraphics for macOS cursor movement
throw new NotImplementedException("Implement macOS cursor movement");
}
}
}