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 public string KeyPressedName
127 return keyPressedName;
131 /* duplicated with KeyPressedName : removed
132 public string KeyPressed
142 /// Keycode for the key pressed.
153 /// Special keys like shift, alt and control which modify the next key pressed.
155 public int KeyModifier
164 /// The time (in ms) that the key event occurred.
175 /// State of the key event.
177 public Key.StateType State
185 public DeviceClassType DeviceClass
189 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 return (DeviceClassType)ret;
197 /// Default Constructor.
199 public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// <param name="keyName">The name of the key pressed or command from the IMF, if later then the some following parameters will be needed</param>
208 /// <param name="keyString">A string of input characters or key pressed</param>
209 /// <param name="keyCode">The unique key code for the key pressed</param>
210 /// <param name="keyModifier">The key modifier for special keys like shift and alt</param>
211 /// <param name="timeStamp">The time (in ms) that the key event occurred</param>
212 /// <param name="keyState">The state of the key event</param>
213 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)
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 /// Checks to see if Shift key modifier has been supplied.
221 /// <returns>True if shift modifier</returns>
222 public bool IsShiftModifier()
224 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 /// Checks to see if Ctrl (control) key modifier has been supplied.
232 /// <returns>True if ctrl modifier</returns>
233 public bool IsCtrlModifier()
235 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 /// Checks to see if Alt key modifier has been supplied.
243 /// <returns>True if alt modifier</returns>
244 public bool IsAltModifier()
246 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 private string keyPressedName
255 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 private string keyPressed
270 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 private int keyModifier
300 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 NDalicPINVOKE.Key_time_set(swigCPtr, value);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326 private Key.StateType state
330 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 /// Enumeration for specifying the state of the key event.
344 public enum StateType