From: <nic...@us...> - 2014-01-14 20:55:18
|
Revision: 4728 http://sourceforge.net/p/mp-plugins/code/4728 Author: nicsergio Date: 2014-01-14 20:55:15 +0000 (Tue, 14 Jan 2014) Log Message: ----------- Modified Paths: -------------- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuterKeyConfig.cs Removed Paths: ------------- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/KeyboardHookWorker.cs Deleted: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/KeyboardHookWorker.cs =================================================================== --- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/KeyboardHookWorker.cs 2014-01-14 15:44:20 UTC (rev 4727) +++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/KeyboardHookWorker.cs 2014-01-14 20:55:15 UTC (rev 4728) @@ -1,91 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Windows.Forms; - -namespace ProcessPlugins.ShortCuter -{ - internal class KeyboardHookWorker //Classe per gestione hook di tastiera su thread separato (problemi con timeout di Windows) - { - #region Delegati/Classi - public delegate bool HookKeyDownDelegate(Keys KeyCode); //Dichiarazione delegato per gestione evento di KeyDown - private class HiddenForm : Form //Classe form nascosta (per attivazione su thread separato) - { - public HiddenForm() - { - Visible = false; - SetTopLevel(false); - } - } - #endregion - - #region Dati - private readonly HookKeyDownDelegate HookKeyDown; //Delegato per gestione evento di KeyDown (passato dal chiamante) - private Thread hookThread; //Thread di attivazione hook - private Form hookForm; //Form del thread per attivazione hook - private KeyboardHook keyboardHook; //Istanza classe KeyboardHook (gestione hook di tastiera) - #endregion - - #region Costruttore - public KeyboardHookWorker(HookKeyDownDelegate hookKeyDown) - { - HookKeyDown = hookKeyDown; //--> assegnazione delegato per gestione evento KeyDown - } - #endregion - - #region Metodi Privati - protected virtual List<Keys> AddHookedKeys() //Metodo virtuale per implementare una lista di tasti da controllare - { //[esecuzione su thread secondario] - return new List<Keys>(); //--> lista vuota (tutti i tasti vengono monitorati) - } - private void Run() //Procedura di avvio thread secondario - { //[esecuzione su thread secondario] - keyboardHook = new KeyboardHook(); //--> creazione hook di tastiera - keyboardHook.HookedKeys = AddHookedKeys(); //--> aggiunta eventuale lista di tasti da monitorare - keyboardHook.KeyDown += new KeyEventHandler(keyboardHook_KeyDown); //--> sottoscrizione evento di KeyDown - hookForm = new HiddenForm(); //--> creazione forma nascosta - Application.Run(hookForm); //--> avvio applicazione con form nascosta - } - #endregion - - #region Metodi Pubblici - public void Start() //Avvio (o ri-avvio) thread di hook - { - Stop(); //--> eventuale stop thread - hookThread = new Thread(Run); //--> creazione thread - hookThread.Priority = ThreadPriority.Highest; //--> impostazione alta priorità (problemi di timeout con Win7) - hookThread.Name = "HookWorker"; //--> impostazione nome - hookThread.Start(); //--> avvio thread - } - public void Stop() //Stop thread di hook - { - if (hookThread != null) - { - if (hookThread.IsAlive) - { - try - { - if (hookForm != null) - hookForm.Invoke((MethodInvoker)delegate //--> invocazione (sul thread secondario) del delegato per stoppare il thread - { - if (keyboardHook != null) - keyboardHook = null; //--> distruzione hook - Application.ExitThread(); //--> terminazione thread secondario - }); - hookThread.Join(); //--> attesa sul thread principale della terminazione del thread secondario - } - catch { } - } - hookThread = null; - } - } - #endregion - - #region Consumazione Eventi - private void keyboardHook_KeyDown(object sender, KeyEventArgs e) //Evento KeyDown intercettato dall'hook - { //[esecuzione su thread secondario] - if (HookKeyDown != null) //Se delegato di gestione evento assegnato - e.Handled = HookKeyDown(e.KeyCode); //--> richiamo del delegato (ritorna true se evento gestito: tasto da non passare al sistema) - } - #endregion - } -} Modified: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj =================================================================== --- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj 2014-01-14 15:44:20 UTC (rev 4727) +++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj 2014-01-14 20:55:15 UTC (rev 4728) @@ -6,7 +6,7 @@ <ProductVersion>8.0.30703</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{20CEBE32-A39E-4A61-B2BD-90BF16E2AEE8}</ProjectGuid> - <OutputType>WinExe</OutputType> + <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>ProcessPlugins.ShortCuter</RootNamespace> <AssemblyName>ShortCuter</AssemblyName> @@ -81,7 +81,6 @@ <Link>VersionInfo.designer.cs</Link> <DependentUpon>VersionInfo.cs</DependentUpon> </Compile> - <Compile Include="KeyboardHookWorker.cs" /> <Compile Include="KeyboardHook.cs" /> <Compile Include="LockKeys.cs" /> <Compile Include="Program.cs" /> Modified: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuterKeyConfig.cs =================================================================== --- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuterKeyConfig.cs 2014-01-14 15:44:20 UTC (rev 4727) +++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuterKeyConfig.cs 2014-01-14 20:55:15 UTC (rev 4728) @@ -1,65 +1,49 @@ using System; +using System.Drawing; using System.Windows.Forms; -using System.Drawing; namespace ProcessPlugins.ShortCuter { public partial class ShortCuterKeyConfig : Form //Form per assegnazione key allo shortcut corrente { #region Dati - private ShortCut mySc; - + private ShortCut mySc; //Istanza classe ShortCut per gestione shorcut corrente private KeyboardHook keyboardHook; //Istanza classe KeyboardHook (gestione hook di tastiera) - #endregion #region Costruttore public ShortCuterKeyConfig(ShortCut currentShortCut, Point startLocation) { InitializeComponent(); - Location = startLocation; - mySc = currentShortCut; - Text = "'" + mySc.Caption + "' ShortCut"; - keyLabel.Text = mySc.Key; - - keyboardHook = new KeyboardHook(); //--> creazione hook di tastiera - keyboardHook.KeyDown += new KeyEventHandler(keyboardHook_KeyDown); //--> sottoscrizione evento di KeyDown - - + Location = startLocation; //--> impostazione posizione form + mySc = currentShortCut; //--> impostazione riferimento a shortcut corrente + Text = "'" + mySc.Caption + "' ShortCut"; //--> titolo della finestra corrispondente a nome shorcut + keyLabel.Text = mySc.Key; //--> visualizzazione tasto correntemente assegnato } #endregion #region Consumazione Eventi - private void okPictureBox_Click(object sender, EventArgs e) - { - mySc.Key = keyLabel.Text; - this.Close(); - } - - private void keyboardHook_KeyDown(object sender, KeyEventArgs e) //Evento KeyDown intercettato dall'hook - { //[esecuzione su thread secondario] - if (ShortCut.ModifierKeys.Contains(e.KeyCode)) - e.Handled = true; //Se il tasto premuto corrisponde ad un modificatore, viene ignorato - else - { - keyLabel.Text = e.KeyCode.ToString(); - e.Handled = true; - } - - } - #endregion - private void ShortCuterKeyConfig_Load(object sender, EventArgs e) { - + keyboardHook = new KeyboardHook(); //--> creazione hook di tastiera + keyboardHook.KeyDown += new KeyEventHandler(keyboardHook_KeyDown); //--> sottoscrizione evento di KeyDown } - private void ShortCuterKeyConfig_FormClosing(object sender, FormClosingEventArgs e) { if (keyboardHook != null) - keyboardHook = null; + keyboardHook = null; //--> distruzione hook } - - + private void okPictureBox_Click(object sender, EventArgs e) + { + mySc.Key = keyLabel.Text; //--> memorizzazione tasto assegnato allo shortcut + this.Close(); //--> chiusura form + } + private void keyboardHook_KeyDown(object sender, KeyEventArgs e) //Evento KeyDown intercettato dall'hook + { + if (!ShortCut.ModifierKeys.Contains(e.KeyCode)) + keyLabel.Text = e.KeyCode.ToString(); //--> visualizzazione tasto premuto, se non corrisponde ad un modificatore + e.Handled = true; //--> il tasto premuto viene ignorato + } + #endregion } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |