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 keyPressedName = value;
135 /* duplicated with KeyPressedName : removed
136 public string KeyPressed
146 /// Keycode for the key pressed.
161 /// Special keys like shift, alt and control which modify the next key pressed.
163 public int KeyModifier
176 /// The time (in ms) that the key event occurred.
191 /// State of the key event.
193 public Key.StateType State
205 public DeviceClassType DeviceClass
209 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 return (DeviceClassType)ret;
217 /// Default Constructor.
219 public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
221 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227 /// <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>
228 /// <param name="keyString">A string of input characters or key pressed</param>
229 /// <param name="keyCode">The unique key code for the key pressed</param>
230 /// <param name="keyModifier">The key modifier for special keys like shift and alt</param>
231 /// <param name="timeStamp">The time (in ms) that the key event occurred</param>
232 /// <param name="keyState">The state of the key event</param>
233 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)
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 /// Checks to see if Shift key modifier has been supplied.
241 /// <returns>True if shift modifier</returns>
242 public bool IsShiftModifier()
244 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// Checks to see if Ctrl (control) key modifier has been supplied.
252 /// <returns>True if ctrl modifier</returns>
253 public bool IsCtrlModifier()
255 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// Checks to see if Alt key modifier has been supplied.
263 /// <returns>True if alt modifier</returns>
264 public bool IsAltModifier()
266 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 private string keyPressedName
275 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 private string keyPressed
290 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 private int keyModifier
320 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335 NDalicPINVOKE.Key_time_set(swigCPtr, value);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 private Key.StateType state
350 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 /// Enumeration for specifying the state of the key event.
364 public enum StateType