1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 /// The key structure is used to store a key press.
23 public class Key : global::System.IDisposable
25 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26 protected bool swigCMemOwn;
28 internal Key(global::System.IntPtr cPtr, bool cMemoryOwn)
30 swigCMemOwn = cMemoryOwn;
31 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39 //A Flag to check who called Dispose(). (By User or DisposeQueue)
40 private bool isDisposeQueued = false;
41 //A Flat to check if it is already disposed.
42 protected bool disposed = false;
48 isDisposeQueued = true;
49 DisposeQueue.Instance.Add(this);
55 //Throw excpetion if Dispose() is called in separate thread.
56 if (!Window.IsInstalled())
58 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
63 Dispose(DisposeTypes.Implicit);
67 Dispose(DisposeTypes.Explicit);
68 System.GC.SuppressFinalize(this);
72 protected virtual void Dispose(DisposeTypes type)
79 if(type == DisposeTypes.Explicit)
82 //Release your own managed resources here.
83 //You should release all of your own disposable objects here.
86 //Release your own unmanaged resources here.
87 //You should not access any managed member here except static instance.
88 //because the execution order of Finalizes is non-deterministic.
90 if (swigCPtr.Handle != global::System.IntPtr.Zero)
95 NDalicPINVOKE.delete_Key(swigCPtr);
97 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103 internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
105 Key ret = new Key(cPtr, false);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 public string DeviceName
114 string ret = NDalicPINVOKE.GetDeviceName(swigCPtr);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 /// Name given to the key pressed.
123 /// <since_tizen> 3 </since_tizen>
124 public string KeyPressedName
128 return keyPressedName;
132 keyPressedName = value;
136 /* duplicated with KeyPressedName : removed
137 public string KeyPressed
147 /// Keycode for the key pressed.
149 /// <since_tizen> 3 </since_tizen>
163 /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
165 /// <since_tizen> 3 </since_tizen>
166 public int KeyModifier
179 /// The time (in ms) that the key event occurred.
181 /// <since_tizen> 3 </since_tizen>
195 /// State of the key event.
197 /// <since_tizen> 3 </since_tizen>
198 public Key.StateType State
210 public DeviceClassType DeviceClass
214 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 return (DeviceClassType)ret;
222 /// The default constructor.
224 /// <since_tizen> 3 </since_tizen>
225 public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
234 /// <param name="keyString">A string of input characters or key pressed.</param>
235 /// <param name="keyCode">The unique key code for the key pressed.</param>
236 /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
237 /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
238 /// <param name="keyState">The state of the key event.</param>
239 internal Key(string keyName, string keyString, int keyCode, int keyModifier, uint timeStamp, Key.StateType keyState) : this(NDalicPINVOKE.new_Key__SWIG_1(keyName, keyString, keyCode, keyModifier, timeStamp, (int)keyState), true)
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 /// Checks to see if the Shift key modifier has been supplied.
247 /// <returns>True if Shift modifier.</returns>
248 /// <since_tizen> 3 </since_tizen>
249 public bool IsShiftModifier()
251 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 /// Checks to see if Ctrl (control) key modifier has been supplied.
259 /// <returns>True if Ctrl modifier.</returns>
260 /// <since_tizen> 3 </since_tizen>
261 public bool IsCtrlModifier()
263 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
264 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 /// Checks to see if Alt key modifier has been supplied.
271 /// <returns>True if Alt modifier.</returns>
272 /// <since_tizen> 3 </since_tizen>
273 public bool IsAltModifier()
275 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 private string keyPressedName
284 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
290 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 private string keyPressed
299 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 private int keyModifier
329 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 NDalicPINVOKE.Key_time_set(swigCPtr, value);
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 private Key.StateType state
359 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371 /// Enumeration for specifying the state of the key event.
373 /// <since_tizen> 3 </since_tizen>
374 public enum StateType