2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 /// The key structure is used to store a key press.
24 public class Key : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
33 internal Key(global::System.IntPtr cPtr, bool cMemoryOwn)
35 swigCMemOwn = cMemoryOwn;
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
41 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
47 /// A Flat to check if it is already disposed.
49 /// <since_tizen> 3 </since_tizen>
50 protected bool disposed = false;
55 /// <since_tizen> 3 </since_tizen>
60 isDisposeQueued = true;
61 DisposeQueue.Instance.Add(this);
68 /// <since_tizen> 3 </since_tizen>
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
91 /// <since_tizen> 3 </since_tizen>
92 protected virtual void Dispose(DisposeTypes type)
99 if(type == DisposeTypes.Explicit)
102 //Release your own managed resources here.
103 //You should release all of your own disposable objects here.
106 //Release your own unmanaged resources here.
107 //You should not access any managed member here except static instance.
108 //because the execution order of Finalizes is non-deterministic.
110 if (swigCPtr.Handle != global::System.IntPtr.Zero)
115 NDalicPINVOKE.delete_Key(swigCPtr);
117 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
123 internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
125 Key ret = new Key(cPtr, false);
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133 /// <since_tizen> 3 </since_tizen>
134 public string DeviceName
138 string ret = NDalicPINVOKE.GetDeviceName(swigCPtr);
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 /// Name given to the key pressed.
147 /// <since_tizen> 3 </since_tizen>
148 public string KeyPressedName
152 return keyPressedName;
156 keyPressedName = value;
160 /* duplicated with KeyPressedName : removed
161 public string KeyPressed
171 /// Keycode for the key pressed.
173 /// <since_tizen> 3 </since_tizen>
187 /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
189 /// <since_tizen> 3 </since_tizen>
190 public int KeyModifier
203 /// The time (in ms) that the key event occurred.
205 /// <since_tizen> 3 </since_tizen>
219 /// State of the key event.
221 /// <since_tizen> 3 </since_tizen>
222 public Key.StateType State
235 /// the device class the key event originated from.
237 /// <since_tizen> 3 </since_tizen>
238 public DeviceClassType DeviceClass
242 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 return (DeviceClassType)ret;
250 /// The default constructor.
252 /// <since_tizen> 3 </since_tizen>
253 public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
262 /// <param name="keyString">A string of input characters or key pressed.</param>
263 /// <param name="keyCode">The unique key code for the key pressed.</param>
264 /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
265 /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
266 /// <param name="keyState">The state of the key event.</param>
267 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)
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 /// Checks to see if the Shift key modifier has been supplied.
275 /// <returns>True if Shift modifier.</returns>
276 /// <since_tizen> 3 </since_tizen>
277 public bool IsShiftModifier()
279 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 /// Checks to see if Ctrl (control) key modifier has been supplied.
287 /// <returns>True if Ctrl modifier.</returns>
288 /// <since_tizen> 3 </since_tizen>
289 public bool IsCtrlModifier()
291 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 /// Checks to see if Alt key modifier has been supplied.
299 /// <returns>True if Alt modifier.</returns>
300 /// <since_tizen> 3 </since_tizen>
301 public bool IsAltModifier()
303 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 private string keyPressedName
312 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 private string keyPressed
327 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 private int keyModifier
357 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 NDalicPINVOKE.Key_time_set(swigCPtr, value);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
378 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 private Key.StateType state
387 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
393 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 /// Enumeration for specifying the state of the key event.
401 /// <since_tizen> 3 </since_tizen>
402 public enum StateType
407 /// <since_tizen> 3 </since_tizen>
412 /// <since_tizen> 3 </since_tizen>
417 /// <since_tizen> 3 </since_tizen>