|
| 1 | +/* |
| 2 | + * Copyright(c) 2024 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.WindowSystem; |
| 23 | + |
| 24 | +namespace Tizen.WindowSystem.InputGeneratorTest |
| 25 | +{ |
| 26 | + class Program : NUIApplication |
| 27 | + { |
| 28 | + protected override void OnCreate() |
| 29 | + { |
| 30 | + base.OnCreate(); |
| 31 | + Initialize(); |
| 32 | + } |
| 33 | + |
| 34 | + void Initialize() |
| 35 | + { |
| 36 | + Window win = Window.Default; |
| 37 | + inputGen = new InputGenerator(); |
| 38 | + |
| 39 | + win.WindowSize = new Size2D(500, 500); |
| 40 | + win.KeyEvent += OnKeyEvent; |
| 41 | + win.BackgroundColor = Color.White; |
| 42 | + |
| 43 | + // Root layout |
| 44 | + View rootView = new View(); |
| 45 | + rootView.Size2D = new Size2D(500, 500); |
| 46 | + rootView.Layout = new LinearLayout() |
| 47 | + { |
| 48 | + LinearOrientation = LinearLayout.Orientation.Vertical, |
| 49 | + }; |
| 50 | + win.Add(rootView); |
| 51 | + |
| 52 | + // Upper area: touch to generate SendKey |
| 53 | + View touchView = new View(); |
| 54 | + touchView.SizeWidth = 500; |
| 55 | + touchView.Weight = 1.0f; |
| 56 | + touchView.SizeHeight = 400; |
| 57 | + touchView.BackgroundColor = Color.White; |
| 58 | + touchView.TouchEvent += OnTouchView; |
| 59 | + rootView.Add(touchView); |
| 60 | + |
| 61 | + centerLabel = new TextLabel("Touch upper area: SendKey test\nTouch counter: 0 / Key counter: 0"); |
| 62 | + centerLabel.HorizontalAlignment = HorizontalAlignment.Center; |
| 63 | + centerLabel.VerticalAlignment = VerticalAlignment.Center; |
| 64 | + centerLabel.TextColor = Color.Black; |
| 65 | + centerLabel.PointSize = 12.0f; |
| 66 | + centerLabel.MultiLine = true; |
| 67 | + centerLabel.HeightResizePolicy = ResizePolicyType.FillToParent; |
| 68 | + centerLabel.WidthResizePolicy = ResizePolicyType.FillToParent; |
| 69 | + touchView.Add(centerLabel); |
| 70 | + |
| 71 | + // Lower area: button to generate SendPointer |
| 72 | + var sendPointerBtn = new Tizen.NUI.Components.Button() |
| 73 | + { |
| 74 | + Text = "SendPointer (generate touch at upper area)", |
| 75 | + SizeWidth = 500, |
| 76 | + SizeHeight = 80, |
| 77 | + PointSize = 10.0f, |
| 78 | + PositionY = 300f |
| 79 | + }; |
| 80 | + sendPointerBtn.Clicked += OnSendPointerClicked; |
| 81 | + rootView.Add(sendPointerBtn); |
| 82 | + } |
| 83 | + |
| 84 | + private void OnKeyEvent(object sender, Window.KeyEventArgs e) |
| 85 | + { |
| 86 | + if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape")) |
| 87 | + { |
| 88 | + Exit(); |
| 89 | + } |
| 90 | + if (e.Key.State == Key.StateType.Down && e.Key.KeyPressedName == "Return") |
| 91 | + { |
| 92 | + keyCounter++; |
| 93 | + UpdateLabel(); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + /// <summary> |
| 98 | + /// Touch on upper area → SendKey("Return") test |
| 99 | + /// </summary> |
| 100 | + private bool OnTouchView(object sender, View.TouchEventArgs e) |
| 101 | + { |
| 102 | + if (e.Touch.GetState(0) == PointStateType.Down) |
| 103 | + { |
| 104 | + touchCounter++; |
| 105 | + UpdateLabel(); |
| 106 | + |
| 107 | + inputGen.SendKey("Return", true); |
| 108 | + inputGen.SendKey("Return", false); |
| 109 | + |
| 110 | + return true; |
| 111 | + } |
| 112 | + return false; |
| 113 | + } |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Button click → SendPointer() generates a touch at (250, 150) which lands on the upper touchView. |
| 117 | + /// This triggers OnTouchView, proving SendPointer works. |
| 118 | + /// </summary> |
| 119 | + private void OnSendPointerClicked(object sender, Tizen.NUI.Components.ClickedEventArgs e) |
| 120 | + { |
| 121 | + inputGen.SendPointer(0, PointerAction.Down, 250, 150, InputGeneratorDevices.Touchscreen); |
| 122 | + inputGen.SendPointer(0, PointerAction.Up, 250, 150, InputGeneratorDevices.Touchscreen); |
| 123 | + } |
| 124 | + |
| 125 | + private void UpdateLabel() |
| 126 | + { |
| 127 | + centerLabel.Text = $"Touch counter: {touchCounter} / Key counter: {keyCounter}"; |
| 128 | + } |
| 129 | + |
| 130 | + static void Main(string[] args) |
| 131 | + { |
| 132 | + var app = new Program(); |
| 133 | + app.Run(args); |
| 134 | + } |
| 135 | + |
| 136 | + private InputGenerator inputGen; |
| 137 | + private TextLabel centerLabel; |
| 138 | + int touchCounter = 0; |
| 139 | + int keyCounter = 0; |
| 140 | + } |
| 141 | +} |
0 commit comments