Analyze the key sequence for different functions. However, it is abstracted from it. For the moment, it is unknown that it can be used for other purposes.

Source: Internet
Author: User
// The following is an abstract class. It mainly looks at the fact that only the logic code contains a very specific type such as keys, which is uncomfortable. It may be used as something else.
Using system. collections. generic; namespace keyboardsynchronizer {public abstract class funcqueue <t> {public bool adding {Get; private set;} private t toggler; Public int ID {Get; private set ;} public int index {Get; private set ;}=-1; public list <t> parameters {Get ;}= new list <t> (); protected abstract t empty {Get;} // <summary> // insert these to stop adding more parameters and res Et this instance. /// </Summary> Public T [] restarter {Get; set;} protected abstract bool isindexelement (T); protected abstract int createnewindex (t ); protected abstract bool equals (t a, t B); Public void insert (t) {If (equals (T, empty) {return;} If (isindexelement (t )) {If (adding) {Add (t) ;}else {Index = createnewindex (t) ;}} else {If (equals (toggler, empty) {toggler = T ;} el Se if (equals (toggler, t) {If (adding) {Add (t);} else {If (Index =-1) {ID ++ ;} else {adding = true ;}}else {If (adding) {Add (t) ;}else {toggler = T; id = 0; index =-1 ;}}} private void add (t) {If (restarter! = NULL & restarter. length> 0 & parameters. count + 1> = restarter. length & equals (restarter [restarter. length-1], t) {var I = parameters. count-1; var J = restarter. length-2; for (; I >=0 & J> = 0;) {If (equals (parameters [I], restarter [J]) {I --; J --; continue;} parameters. add (t); return;} adding = false; id = 0; toggler = empty; Index =-1; parameters. clear ();} else {parameters. add (t );}}}}
// The following is an implementation class for customizing shortcut keys. Press the next key X once or multiple times to differentiate different functions, and then press a number to specify the first parameter, press X again to end the first parameter and enter more parameters.
using System.Linq;using System.Windows.Forms;namespace KeyboardSynchronizer {    public class KeysQueue : FuncQueue<Keys> {        static Keys[] numbers = { Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9 };     public KeysQueue(){
      Restarter = new[] { Keys.S, Keys.T, Keys.O, Keys.P };
     }   protected override Keys Empty { get { return Keys.None; } } protected override bool Equals(Keys a, Keys b) { return a == b; } protected override int CreateNewIndex(Keys t) { var v = (Index > -1 ? Index.ToString() : string.Empty) + t.ToString()[1]; try { return int.Parse(v); } catch { return Index; } } protected override bool IsIndexElement(Keys t) { return numbers.Contains(t); } }}
 

 

 

 

Analyze the key sequence for different functions. However, it is abstracted from it. For the moment, it is unknown that it can be used for other purposes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.