Release 12.0.0.18258
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.WindowSystem.InputGenerator / Tizen.NUI.WindowSystem.InputGenerator.cs
1 /*
2  * Copyright(c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using Tizen;
20 using Tizen.NUI;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.WindowSystem;
23 using System.Collections.Generic;
24
25 namespace Tizen.NUI.WindowSystem
26 {
27     class Program : NUIApplication
28     {
29         protected override void OnCreate()
30         {
31             base.OnCreate();
32             Initialize();
33         }
34
35         void Initialize()
36         {
37             Window win = Window.Instance;
38             inputGen = new InputGenerator(InputGenerator.DeviceType.All, null);
39
40             win.WindowSize = new Size2D(500, 500);
41             win.KeyEvent += OnKeyEvent;
42             win.BackgroundColor = Color.White;
43
44             View windowView = new View();
45             windowView.Size2D = new Size2D(500, 500);
46             windowView.BackgroundColor = Color.White;
47             windowView.TouchEvent += OnTouchEvent;
48             win.Add(windowView);
49
50             centerLabel = new TextLabel("InputGenerator Sample, Click to generate Return Key.");
51             centerLabel.HorizontalAlignment = HorizontalAlignment.Center;
52             centerLabel.VerticalAlignment = VerticalAlignment.Center;
53             centerLabel.TextColor = Color.Black;
54             centerLabel.PointSize = 12.0f;
55             centerLabel.HeightResizePolicy = ResizePolicyType.FillToParent;
56             centerLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
57             windowView.Add(centerLabel);
58
59             repeatCounter = 0;
60         }
61
62         private void OnKeyEvent(object sender, Window.KeyEventArgs e)
63         {
64             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
65             {
66                 Exit();
67             }
68             if (e.Key.State == Key.StateType.Down && e.Key.KeyPressedName == "Return")
69             {
70                 repeatCounter++;
71                 centerLabel.Text = "Return Key Pressed, counter: " + repeatCounter.ToString();
72             }
73         }
74
75         private bool OnTouchEvent(object sender, View.TouchEventArgs e)
76         {
77             if (e.Touch.GetState(0) == PointStateType.Down)
78             {
79                 inputGen.GenerateKey("Return", 1);
80                 inputGen.GenerateKey("Return", 0);
81
82                 return true;
83             }
84
85             return false;
86         }
87
88         static void Main(string[] args)
89         {
90             var app = new Program();
91             app.Run(args);
92         }
93
94         private InputGenerator inputGen;
95         private TextLabel centerLabel;
96         int repeatCounter = 0;
97     }
98 }