diff --git a/App.xaml.cs b/App.xaml.cs
index 1d4c64b..981620c 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -1,19 +1,30 @@
-using System.Configuration;
-using System.Data;
+using System;
+using System.Threading;
using System.Windows;
using Application = System.Windows.Application;
namespace EscribePassword
{
- ///
- /// Interaction logic for App.xaml
- ///
public partial class App : Application
{
+ private static Mutex _mutex = null;
+
public KeyboardHelper PasteLogic { get; } = new KeyboardHelper();
protected override void OnStartup(StartupEventArgs e)
{
+ const string appName = "EscribePasswordApp";
+ bool createdNew;
+
+ _mutex = new Mutex(true, appName, out createdNew);
+
+ if (!createdNew)
+ {
+ // Hay otra instancia en ejecución, cerramos esta instancia
+ Application.Current.Shutdown();
+ return;
+ }
+
base.OnStartup(e);
PasteLogic.SaveCurrentWindow();
SetInitialWindowPosition();
@@ -26,18 +37,12 @@ namespace EscribePassword
if (mainWindow != null)
{
-
- // Obtener la posición del cursor
var cursorPosition = System.Windows.Forms.Cursor.Position;
-
- // Determinar en qué pantalla está el cursor
var screen = Screen.FromPoint(cursorPosition);
- // Determinar la posición inicial
double newLeft = screenRect.Right;
double newTop = screenRect.Top;
- // Verificar si la ventana se posiciona fuera de la pantalla y ajustarla si es necesario
if (newLeft < screenRect.Left)
{
newLeft = screenRect.Left;
@@ -48,11 +53,9 @@ namespace EscribePassword
newLeft = screen.WorkingArea.Right - mainWindow.Width;
}
- // Aplicar la nueva posición
mainWindow.Left = newLeft;
mainWindow.Top = newTop;
}
}
}
-
}
diff --git a/EscribePassword.csproj b/EscribePassword.csproj
index 8460c40..b81735f 100644
--- a/EscribePassword.csproj
+++ b/EscribePassword.csproj
@@ -13,6 +13,7 @@
+
diff --git a/KeyboardHelper.cs b/KeyboardHelper.cs
index 59581aa..2f66879 100644
--- a/KeyboardHelper.cs
+++ b/KeyboardHelper.cs
@@ -2,7 +2,6 @@
using WindowsInput.Native;
using WindowsInput;
using System.Windows;
-using EscribePassword;
using CommunityToolkit.Mvvm.ComponentModel;
namespace EscribePassword
@@ -15,6 +14,10 @@ namespace EscribePassword
[ObservableProperty]
private string password;
+
+ [ObservableProperty]
+ private string categoria;
+
}
public class KeyboardHelper
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 88c7933..63169ea 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -3,7 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EscribePassword" mc:Ignorable="d" Title="MainWindow" Height="450" Width="300"
- AllowsTransparency="True" WindowStyle="None" MouseDown="Window_MouseDown">
+ AllowsTransparency="True" WindowStyle="None" MouseDown="Window_MouseDown" Topmost="True">
@@ -12,30 +12,56 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 4c9b70c..e004ff1 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -1,19 +1,16 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.Json;
using System.IO;
using System.Windows;
-using WindowsInput;
-using WindowsInput.Native;
using Application = System.Windows.Application;
using System.Windows.Input;
using MouseButton = System.Windows.Input.MouseButton;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Input;
-using ListBox = System.Windows.Controls.ListBox;
+using Gma.System.MouseKeyHook;
+using MouseEventArgs = System.Windows.Forms.MouseEventArgs;
+
+
namespace EscribePassword
{
@@ -24,38 +21,122 @@ namespace EscribePassword
///
public partial class MainWindow : Window
{
+ private IKeyboardMouseEvents _globalHook;
+
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
+ this.MouseWheel += MainWindow_Wheel;
+ HookManager();
}
+
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
((App)Application.Current).SetInitialWindowPosition();
}
+ private void MainWindow_Wheel(object sender, MouseWheelEventArgs e)
+ {
+ if (DataContext is MView mv)
+ mv.OnWheel(sender, e);
+ }
+
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
this.DragMove();
}
- }
+ else if (e.ChangedButton == MouseButton.Middle)
+ {
+ if (DataContext is MView mv && mv.SelectedPassword != null)
+ {
+ mv.UtilizarCommand.Execute(mv.SelectedPassword);
+ e.Handled = true; // Suprimir el evento
+ }
+ }
+ }
+
+ private void HookManager()
+ {
+ _globalHook = Hook.GlobalEvents();
+ _globalHook.MouseWheel += GlobalHookMouseWheel;
+ _globalHook.MouseDownExt += GlobalHookMouseDown;
+ }
+
+ private void GlobalHookMouseDown(object sender, MouseEventExtArgs e)
+ {
+ if (e.Button == System.Windows.Forms.MouseButtons.Middle)
+ {
+ var mouseButtonEventArgs = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Middle)
+ {
+ RoutedEvent = UIElement.MouseDownEvent
+ };
+ Window_MouseDown(sender, mouseButtonEventArgs);
+ }
+ }
+
+ private void GlobalHookMouseWheel(object sender, MouseEventArgs e)
+ {
+ // Convierte MouseEventArgs a MouseWheelEventArgs
+ var wheelArgs = new MouseWheelEventArgs(Mouse.PrimaryDevice, 0, e.Delta)
+ {
+ RoutedEvent = UIElement.MouseWheelEvent
+ };
+ MainWindow_Wheel(sender, wheelArgs);
+ }
+
+ protected override void OnClosed(EventArgs e)
+ {
+ _globalHook.MouseWheel -= GlobalHookMouseWheel;
+ _globalHook.MouseDownExt -= GlobalHookMouseDown;
+ _globalHook.Dispose();
+ base.OnClosed(e);
+ }
}
+
+
public partial class MView : ObservableObject
{
[ObservableProperty]
private ObservableCollection passwords;
+ [ObservableProperty]
+ private ObservableCollection top_passwords;
+
[ObservableProperty]
private Passwords selectedPassword;
+ public void OnWheel(object sender, MouseWheelEventArgs e)
+ {
+ if (Passwords.Count == 0) return;
+
+ var index = Passwords.IndexOf(SelectedPassword);
+ var max = Passwords.Count;
+ if (e.Delta > 0)
+ index++;
+ else index--;
+ if (index < 0) index = max-1;
+ if (index >= max) index = 0;
+
+ SelectedPassword = Passwords[index];
+ }
+
+ partial void OnSelectedPasswordChanged(Passwords value)
+ {
+ Top_passwords.Clear();
+ Top_passwords.Add(value);
+ }
+
public MView()
{
// Suscribirse al evento de cierre de la aplicación
Application.Current.Exit += OnApplicationExit;
+ top_passwords = new ObservableCollection();
passwords = new ObservableCollection(EstadoPersistente.Instance.Passwords);
+ SelectedPassword = passwords.FirstOrDefault();
}
private void OnApplicationExit(object sender, ExitEventArgs e)