Create virtual keyboard using C# Winform Application

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
 
namespace VirtualKeyboardDemo
{
    /// <summary>
    /// Geovin Du 涂聚文
    /// http://www.codeproject.com/KB/miscctrl/touchscreenkeyboard.aspx
    /// http://blogs.microsoft.co.il/blogs/tamir/archive/2008/02/13/custom-editors-accessibility-and-attached-properties.aspx
    /// http://www.codeproject.com/KB/scripting/jvk.aspx
    /// http://www.dreamincode.net/forums/topic/107179-virtual-keyboard/
    ///
    /// </summary>
    public partial class Form2 : Form
    {
 
        private const uint SWP_NOSIZE = 0x0001;
        private const uint SWP_NOMOVE = 0x0002;
        private const uint SWP_NOZORDER = 0x0004;
        private const uint SWP_NOREDRAW = 0x0008;
        private const uint SWP_NOACTIVATE = 0x0010;
        private const uint SWP_FRAMECHANGED = 0x0020;
        private const uint SWP_SHOWWINDOW = 0x0040;
        private const uint SWP_HIDEWINDOW = 0x0080;
        private const uint SWP_NOCOPYBITS = 0x0100;
        private const uint SWP_NOOWNERZORDER = 0x0200;
        private const uint SWP_NOSENDCHANGING = 0x0400;
        private int handle;
        #region SendMessage Constants
 
        private const int WM_LBUTTONDOWN = 0x0201;
        private const int WM_LBUTTONUP = 0x0202;
        private const int WM_LBUTTONDBLCLK = 0x0203;
        private const int WM_RBUTTONDOWN = 0x0204;
        private const int WM_RBUTTONUP = 0x0205;
        private const int WM_RBUTTONDBLCLK = 0x0206;
        private const int WM_MOUSEMOVE = 0x0200;
        private const int WM_KEYDOWN = 0x100;
        private const int WM_KEYUP = 0x0101;
        private const int WM_CHAR = 0x0102;
        #endregion SendMessage Constants
        #region API fonction
        //Public Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long 
        //this function gets active window identify number == (8975651603260375040) 
        [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetActiveWindow", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
 
        public static extern long SetActiveWindow(long hwnd);
        [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "keybd_event", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
        public static extern long keybd_event(byte bVk, byte bScan, long dwFlags, long dwExtraInfo);
 
        #endregion
        static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
        static readonly IntPtr HWND_TOP = new IntPtr(0);
        const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
        #region Virtual Keys Constants
        private const int VK_LBUTTON = 0X1; //Left mouse button. 
        private const int VK_RBUTTON = 0X2; //Right mouse button. 
        private const int VK_CANCEL = 0X3; //Used for control-break processing. 
        private const int VK_MBUTTON = 0X4; //''Middle mouse button (3-button mouse). 
        private const int KEYEVENTF_KEYUP = 0X2; // Release key 
        private const int VK_OEM_PERIOD = 0XBE; //.
        private const int KEYEVENTF_EXTENDEDKEY = 0X1;
        private const int VK_STARTKEY = 0X5B; //Start Menu key 
        private bool lockbool;
        private bool numlockbool;
        private bool ctrlbool;
        private bool onoff;
        private const int VK_OEM_COMMA = 0XBC; //, comma 
        public const int VK_0 = 0x30;
        public const int VK_1 = 0x31;
        public const int VK_2 = 0x32;
        public const int VK_3 = 0x33;
        public const int VK_4 = 0x34;
        public const int VK_5 = 0x35;
        public const int VK_6 = 0x36;
        public const int VK_7 = 0x37;
        public const int VK_8 = 0x38;
        public const int VK_9 = 0x39;
        public const int VK_A = 0x41;
        public const int VK_B = 0x42;
        public const int VK_C = 0x43;
        public const int VK_D = 0x44;
        public const int VK_E = 0x45;
        public const int VK_F = 0x46;
        public const int VK_G = 0x47;
        public const int VK_H = 0x48;
        public const int VK_I = 0x49;
        public const int VK_J = 0x4A;
        public const int VK_K = 0x4B;
        public const int VK_L = 0x4C;
        public const int VK_M = 0x4D;
        public const int VK_N = 0x4E;
        public const int VK_O = 0x4F;
        public const int VK_P = 0x50;
        public const int VK_Q = 0x51;
        public const int VK_R = 0x52;
        public const int VK_S = 0x53;
        public const int VK_T = 0x54;
        public const int VK_U = 0x55;
        public const int VK_V = 0x56;
        public const int VK_W = 0x57;
        public const int VK_X = 0x58;
        public const int VK_Y = 0x59;
        public const int VK_Z = 0x5A;
        public const int VK_BACK = 0x08;
        public const int VK_TAB = 0x09;
        public const int VK_CLEAR = 0x0C;
        public const int VK_RETURN = 0x0D;
        public const int VK_SHIFT = 0x10;
        public const int VK_CONTROL = 0x11;
        public const int VK_MENU = 0x12;
        public const int VK_PAUSE = 0x13;
        public const int VK_CAPITAL = 0x14;
        public const int VK_KANA = 0x15;
        public const int VK_HANGEUL = 0x15;
        public const int VK_HANGUL = 0x15;
        public const int VK_JUNJA = 0x17;
        public const int VK_FINAL = 0x18;
        public const int VK_HANJA = 0x19;
        public const int VK_KANJI = 0x19;
        public const int VK_ESCAPE = 0x1B;
        public const int VK_CONVERT = 0x1C;
        public const int VK_NONCONVERT = 0x1D;
        public const int VK_ACCEPT = 0x1E;
        public const int VK_MODECHANGE = 0x1F;
        public const int VK_SPACE = 0x20;
        public const int VK_PRIOR = 0x21;
        public const int VK_NEXT = 0x22;
        public const int VK_END = 0x23;
        public const int VK_HOME = 0x24;
        public const int VK_LEFT = 0x25;
        public const int VK_UP = 0x26;
        public const int VK_RIGHT = 0x27;
        public const int VK_DOWN = 0x28;
        public const int VK_SELECT = 0x29;
        public const int VK_PRINT = 0x2A;
        public const int VK_EXECUTE = 0x2B;
        public const int VK_SNAPSHOT = 0x2C;
        public const int VK_INSERT = 0x2D;
        public const int VK_DELETE = 0x2E;
        public const int VK_HELP = 0x2F;
        public const int VK_LWIN = 0x5B;
        public const int VK_RWIN = 0x5C;
        public const int VK_APPS = 0x5D;
        public const int VK_SLEEP = 0x5F;
        public const int VK_NUMPAD0 = 0x60;
        public const int VK_NUMPAD1 = 0x61;
        public const int VK_NUMPAD2 = 0x62;
        public const int VK_NUMPAD3 = 0x63;
        public const int VK_NUMPAD4 = 0x64;
        public const int VK_NUMPAD5 = 0x65;
        public const int VK_NUMPAD6 = 0x66;
        public const int VK_NUMPAD7 = 0x67;
        public const int VK_NUMPAD8 = 0x68;
        public const int VK_NUMPAD9 = 0x69;
        public const int VK_MULTIPLY = 0x6A;
        public const int VK_ADD = 0x6B;
        public const int VK_SEPARATOR = 0x6C;
        public const int VK_SUBTRACT = 0x6D;
        public const int VK_DECIMAL = 0x6E;
        public const int VK_DIVIDE = 0x6F;
        public const int VK_F1 = 0x70;
        public const int VK_F2 = 0x71;
        public const int VK_F3 = 0x72;
        public const int VK_F4 = 0x73;
        public const int VK_F5 = 0x74;
        public const int VK_F6 = 0x75;
        public const int VK_F7 = 0x76;
        public const int VK_F8 = 0x77;
        public const int VK_F9 = 0x78;
        public const int VK_F10 = 0x79;
        public const int VK_F11 = 0x7A;
        public const int VK_F12 = 0x7B;
        public const int VK_F13 = 0x7C;
        public const int VK_F14 = 0x7D;
        public const int VK_F15 = 0x7E;
        public const int VK_F16 = 0x7F;
        public const int VK_F17 = 0x80;
        public const int VK_F18 = 0x81;
        public const int VK_F19 = 0x82;
        public const int VK_F20 = 0x83;
        public const int VK_F21 = 0x84;
        public const int VK_F22 = 0x85;
        public const int VK_F23 = 0x86;
        public const int VK_F24 = 0x87;
        public const int VK_NUMLOCK = 0x90;
        public const int VK_SCROLL = 0x91;
        #endregion Virtual Keys Constants
 
        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        [DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,int Y, int cx, int cy, uint uFlags);
        [DllImport("user32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);
        [DllImport("user32.dll", CharSet = CharSet.Auto)] // used for button-down & button-up 
        private static extern int PostMessage(int hWnd, int msg, int wParam, IntPtr lParam);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr SetFocus(IntPtr hWnd);   
 
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
 
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Cursor.Position = new Point(5,763);
            try
            {
                Button key = (Button)sender;
                whichbuttonpushed(key.Name);
                SetActiveWindow(8975651603260375040); //This Line Very Impportant 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            finally
            {
                SetActiveWindow(8975651603260375040);
            
        }
 
         public void SetFocus() 
        
 
            SetForegroundWindow(new IntPtr(this.handle)); 
 
        }   
 
    public void SendLeftButtonDown(int x, int y) 
    
 
        PostMessage(handle, WM_LBUTTONDOWN, 0, new IntPtr(y * 0x10000 + x)); 
 
    }    
    public void SendLeftButtonUp(int x, int y) 
    
        PostMessage(handle, WM_LBUTTONUP, 0, new IntPtr(y * 0x10000 + x)); 
 
    }  
    public void SendLeftButtondblclick(int x, int y) 
    
        PostMessage(handle, WM_LBUTTONDBLCLK, 0, new IntPtr(y * 0x10000 + x));
 
    
        public void SendRightButtonDown(int x, int y) 
    
 
        PostMessage(handle, WM_RBUTTONDOWN, 0, new IntPtr(y * 0x10000 + x)); 
 
    
    public void SendRightButtonUp(int x, int y) 
    
        PostMessage(handle, WM_RBUTTONUP, 0, new IntPtr(y * 0x10000 + x)); 
 
    
    public void SendRightButtondblclick(int x, int y) 
    {
 
        PostMessage(handle, WM_RBUTTONDBLCLK, 0, new IntPtr(y * 0x10000 + x)); 
 
    
    public void SendMouseMove(int x, int y) 
    
        PostMessage(handle, WM_MOUSEMOVE, 0, new IntPtr(y * 0x10000 + x)); 
 
    }
    public void SendKeyDown(int key) 
    
        PostMessage(handle, WM_KEYDOWN, key, IntPtr.Zero); 
    }
    public void SendKeyUp(int key) 
    
 
        PostMessage(handle, WM_KEYUP, key, new IntPtr(1)); 
 
    
    public void SendChar(char c) 
    
 
        SendMessage(handle, WM_CHAR, c, IntPtr.Zero); 
    }  
 
    public void SendString(string s) 
    
 
        foreach (char c in s) SendChar(c); 
    }    
 
        // forcus 
        public void MouseMoved(object sender, MouseEventArgs e)
        
            label1.Text = String.Format("x={0} y={1}", e.X, e.Y);          
 
        }
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            label1.Text = "You Clicked on this button";
            SendKeys.Send("{CAPSLOCK}");
 
        }
        private void Form1_Activated(object sender, EventArgs e)
        {
 
            SendKeys.Send("{CAPSLOCK}");
        }
        // end 
        // function key 
        #region which button pushed function
        //INSTANT C# NOTE: These were formerly VB static local variables:
        private int screenshot_i;
        public string whichbuttonpushed(string _sender)
        {
            try
            {
                SetActiveWindow(8975651603260375040); //Set focus Active window 
                //I found this number("8975651603260375040") via getactivewindow method. 
                switch (_sender)
                {
                    case "btna":
                        keybd_event(VK_A, 0, 0, 0);
                        keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnb":
                        keybd_event(VK_B, 0, 0, 0);
                        keybd_event(VK_B, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnc":
                        keybd_event(VK_C, 0, 0, 0);
                        keybd_event(VK_C, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btn_c":
                        keybd_event(VK_C, 0, 0, 0);
                        keybd_event(VK_C, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnd":
                        keybd_event(VK_D, 0, 0, 0);
                        keybd_event(VK_D, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btne":
                        keybd_event(VK_E, 0, 0, 0);
                        keybd_event(VK_E, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf":
                        keybd_event(VK_F, 0, 0, 0);
                        keybd_event(VK_F, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btng":
                        keybd_event(VK_G, 0, 0, 0);
                        keybd_event(VK_G, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btn_g":
                        keybd_event(VK_G, 0, 0, 0);
                        keybd_event(VK_G, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnh":
                        keybd_event(VK_H, 0, 0, 0);
                        keybd_event(VK_H, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btn_i":
                        keybd_event(VK_I, 0, 0, 0);
                        keybd_event(VK_I, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btni":
                        keybd_event(VK_I, 0, 0, 0);
                        keybd_event(VK_I, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnj":
                        keybd_event(VK_J, 0, 0, 0);
                        keybd_event(VK_J, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnk":
                        keybd_event(VK_K, 0, 0, 0);
                        keybd_event(VK_K, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnl":
                        keybd_event(VK_L, 0, 0, 0);
                        keybd_event(VK_L, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnm":
                        keybd_event(VK_M, 0, 0, 0);
                        keybd_event(VK_M, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnn":
                        keybd_event(VK_N, 0, 0, 0);
                        keybd_event(VK_N, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btno":
                        keybd_event(VK_O, 0, 0, 0);
                        keybd_event(VK_O, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btn_o":
                        keybd_event(VK_O, 0, 0, 0);
                        keybd_event(VK_O, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnp":
                        keybd_event(VK_P, 0, 0, 0);
                        keybd_event(VK_P, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnr":
                        keybd_event(VK_R, 0, 0, 0);
                        keybd_event(VK_R, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btns":
                        keybd_event(VK_S, 0, 0, 0);
                        keybd_event(VK_S, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btn_s":
                        keybd_event(VK_S, 0, 0, 0);
                        keybd_event(VK_S, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnt":
                        keybd_event(VK_T, 0, 0, 0);
                        keybd_event(VK_T, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnu":
                        keybd_event(VK_U, 0, 0, 0);
                        keybd_event(VK_U, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btn_u":
                        keybd_event(VK_U, 0, 0, 0);
                        keybd_event(VK_U, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnv":
                        keybd_event(VK_V, 0, 0, 0);
                        keybd_event(VK_V, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btny":
                        keybd_event(VK_Y, 0, 0, 0);
                        keybd_event(VK_Y, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnz":
                        keybd_event(VK_Z, 0, 0, 0);
                        keybd_event(VK_Z, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnw":
                        keybd_event(VK_W, 0, 0, 0);
                        keybd_event(VK_W, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnq":
                        keybd_event(VK_Q, 0, 0, 0);
                        keybd_event(VK_Q, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnx":
                        keybd_event(VK_X, 0, 0, 0);
                        keybd_event(VK_X, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        //*************************************************************************************** 
                        break;
                    case "btnnokta": //"." 
                        keybd_event(VK_OEM_PERIOD, 0, 0, 0);
                        keybd_event(VK_OEM_PERIOD, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnesc":
                        keybd_event(VK_ESCAPE, 0, 0, 0);
                        keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf1":
                        keybd_event(VK_F1, 0, 0, 0);
                        keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf2":
                        keybd_event(VK_F2, 0, 0, 0);
                        keybd_event(VK_F2, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf3":
                        keybd_event(VK_F3, 0, 0, 0);
                        keybd_event(VK_F3, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();                       
                        break;
                    case "btnf4":
                        keybd_event(VK_F4, 0, 0, 0);
                        keybd_event(VK_F4, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf5":
                        keybd_event(VK_F5, 0, 0, 0);
                        keybd_event(VK_F5, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf6":
                        keybd_event(VK_F6, 0, 0, 0);
                        keybd_event(VK_F6, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf7":
                        keybd_event(VK_F7, 0, 0, 0);
                        keybd_event(VK_F7, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btnf8":
                        keybd_event(VK_F8, 0, 0, 0);
                        keybd_event(VK_F8, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                    case "btn9":
                        keybd_event(VK_9, 0, 0, 0);
                        keybd_event(VK_9, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btncarpi": // *                //  
                        keybd_event(VK_MULTIPLY, 0, 0, 0);
                        keybd_event(VK_MULTIPLY, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
                    case "btneksi": // - 
                        keybd_event(VK_SUBTRACT, 0, 0, 0);
                        keybd_event(VK_SUBTRACT, 0, KEYEVENTF_KEYUP, 0);
                        shiftrelease();
                        altrelease();
                        leftaltrelease();
                        break;
 
                }
                return null;
            }
            catch (Exception ex)
            {
                return null;
            }
            //INSTANT C# NOTE: Inserted the following 'return' since all code paths must return a value in C#:
            return null;
        }
 
        #endregion
        // alt          
        #region shift ,altgr and alt release sub
        public void shiftrelease()
        {
            btnsolshift.BackColor = Color.FromArgb(224, 224, 224);
            btnsagshift.BackColor = Color.FromArgb(224, 224, 224);
            keybd_event(VK_SHIFT, 0, 2, 0);
        }
        public void altrelease()
        {
            keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | 2, 0);
            btnsagaltgr.BackColor = Color.FromArgb(224, 224, 224);
        }
        public void leftaltrelease()
        {
            keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
            btnsolalt.BackColor = Color.FromArgb(224, 224, 224);
        }
        #endregion
        // numlock 
       #region numlock function
        public string numlockfunc(string numlock_tus, bool open_close)
        {
            try
            {
                if (open_close == false) //numlock opened 
                {
                    switch (numlock_tus)
                    {
                        case "btnnumlockbolu":
                            keybd_event(VK_DIVIDE, 0, 0, 0);
                            keybd_event(VK_DIVIDE, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockcarpi":
                            keybd_event(VK_MULTIPLY, 0, 0, 0);
                            keybd_event(VK_MULTIPLY, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockeksi":
                            keybd_event(VK_SUBTRACT, 0, 0, 0);
                            keybd_event(VK_SUBTRACT, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockarti":
                            keybd_event(VK_ADD, 0, 0, 0);
                            keybd_event(VK_ADD, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockenter":
                            keybd_event(VK_RETURN, 0, 0, 0);
                            keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlocknokta":
                            keybd_event(VK_DECIMAL, 0, 0, 0);
                            keybd_event(VK_DECIMAL, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock0":
                            keybd_event(VK_NUMPAD0, 0, 0, 0);
                            keybd_event(VK_NUMPAD0, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock1":
                            keybd_event(VK_NUMPAD1, 0, 0, 0);
                            keybd_event(VK_NUMPAD1, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock2":
                            keybd_event(VK_NUMPAD2, 0, 0, 0);
                            keybd_event(VK_NUMPAD2, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock3":
                            keybd_event(VK_NUMPAD3, 0, 0, 0);
                            keybd_event(VK_NUMPAD3, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock4":
                            keybd_event(VK_NUMPAD4, 0, 0, 0);
                            keybd_event(VK_NUMPAD4, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock5":
                            keybd_event(VK_NUMPAD5, 0, 0, 0);
                            keybd_event(VK_NUMPAD5, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock6":
                            keybd_event(VK_NUMPAD6, 0, 0, 0);
                            keybd_event(VK_NUMPAD6, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock7":
                            keybd_event(VK_NUMPAD7, 0, 0, 0);
                            keybd_event(VK_NUMPAD7, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock8":
                            keybd_event(VK_NUMPAD8, 0, 0, 0);
                            keybd_event(VK_NUMPAD8, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock9":
                            keybd_event(VK_NUMPAD9, 0, 0, 0);
                            keybd_event(VK_NUMPAD9, 0, KEYEVENTF_KEYUP, 0);
                            break;
                    }
                }
                else //numlock closed 
                {
                    switch (numlock_tus)
                    {
                        case "btnnumlockbolu":
                            keybd_event(VK_DIVIDE, 0, 0, 0);
                            keybd_event(VK_DIVIDE, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockcarpi":
                            keybd_event(VK_MULTIPLY, 0, 0, 0);
                            keybd_event(VK_MULTIPLY, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockeksi":
                            keybd_event(VK_SUBTRACT, 0, 0, 0);
                            keybd_event(VK_SUBTRACT, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockarti":
                            keybd_event(VK_ADD, 0, 0, 0);
                            keybd_event(VK_ADD, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlockenter":
                            keybd_event(VK_RETURN, 0, 0, 0);
                            keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlocknokta":
                            keybd_event(VK_DELETE, 0, 0, 0);
                            keybd_event(VK_DELETE, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock0":
                            keybd_event(VK_INSERT, 0, 0, 0);
                            keybd_event(VK_INSERT, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock1":
                            keybd_event(VK_END, 0, 0, 0);
                            keybd_event(VK_END, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock2":
                            keybd_event(VK_DOWN, 0, 0, 0);
                            keybd_event(VK_DOWN, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock3":
                            keybd_event(VK_NEXT, 0, 0, 0);
                            keybd_event(VK_NEXT, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock4":
                            keybd_event(VK_LEFT, 0, 0, 0);
                            keybd_event(VK_LEFT, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock5":
                            break;
                        case "btnnumlock6":
                            keybd_event(VK_RIGHT, 0, 0, 0);
                            keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock7":
                            keybd_event(VK_HOME, 0, 0, 0);
                            keybd_event(VK_HOME, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock8":
                            keybd_event(VK_UP, 0, 0, 0);
                            keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0);
                            break;
                        case "btnnumlock9":
                            keybd_event(VK_PRIOR, 0, 0, 0);
                            keybd_event(VK_PRIOR, 0, KEYEVENTF_KEYUP, 0);
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
 
            //INSTANT C# NOTE: Inserted the following 'return' since all code paths must return a value in C#:
            return null;
 
        }
 
        #endregion
        private void btn1_Click(object sender, EventArgs e)
        {
 
            try
            {               
                Button key = (Button)sender;
                whichbuttonpushed(key.Name);
                SetActiveWindow(8975651603260375040); //This Line Very Impportant
            }
            catch (Exception ex)
            {
 
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
 
            }
            finally
            {
                SetActiveWindow(8975651603260375040);
            }
 
        }
        private void btnlock_Click(object sender, EventArgs e)
        {
            try
            {
                Button key = (Button)sender;
                whichbuttonpushed(key.Name);
                SetActiveWindow(8975651603260375040); //This Line Very Impportant 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            finally
            {
 
                SetActiveWindow(8975651603260375040);
            }
        }
        private void btnsolwindows_Click(object sender, EventArgs e)
        {
            try
            {
                Button key = (Button)sender;
                whichbuttonpushed(key.Name);
                SetActiveWindow(8975651603260375040); //This Line Very Impportant 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
 
            finally
            {
                SetActiveWindow(8975651603260375040);
            }
 
        }
        private void btnsolshift_Click(object sender, EventArgs e)
        {
 
            try
            {
                Button key = (Button)sender;
                whichbuttonpushed(key.Name);
                SetActiveWindow(8975651603260375040); //This Line Very Impportant 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            finally
            {
                SetActiveWindow(8975651603260375040);
            }
        }
        private void btn2_Click(object sender, EventArgs e)
        {
            try
            {
                Button key = (Button)sender;
                whichbuttonpushed(key.Name);
                SetActiveWindow(8975651603260375040); //This Line Very Impportant 
 
            }
            catch (Exception ex)
            {
 
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            finally
            {
                SetActiveWindow(8975651603260375040);
            }
 
        
 
    }
}
posted @   ®Geovin Du Dream Park™  阅读(9010)  评论(1编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
< 2011年4月 >
27 28 29 30 31 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
1 2 3 4 5 6 7
点击右上角即可分享
微信分享提示