KeyEvents.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* INRIA 2005 */
00003 /* Allan CORNET */
00004 /*-----------------------------------------------------------------------------------*/
00005 #include "KeyEvents.h"
00006 /*-----------------------------------------------------------------------------------*/
00007 extern int check_pointer_win __PARAMS ((int *x1,int *y1,int *win));
00008 /*-----------------------------------------------------------------------------------*/
00009 #define CTRL_KEY 1000
00010 #define SHIFT_KEY 2000
00011 #ifndef VK_SLEEP
00012   #define VK_SLEEP 0x5F
00013 #endif
00014 
00015 /* Code à la linux */
00016 #define SCI_VK_CANCEL   65288
00017 #define SCI_VK_PAUSE    65299
00018 #define SCI_VK_SLEEP    65300 
00019 #define SCI_VK_INSERT   65379
00020 #define SCI_VK_DELETE   65535
00021 #define SCI_VK_END      65367
00022 #define SCI_VK_HOME     65360
00023 #define SCI_VK_PRIOR    65365
00024 #define SCI_VK_NEXT     65366
00025 #define SCI_VK_BACK     65289
00026 #define SCI_VK_NUMLOCK 65407 
00027 #define SCI_VK_SCROLL 65300 
00028 #define SCI_VK_SNAPSHOT 0
00029 #define SCI_VK_TAB 65289
00030 #define SCI_VK_ESCAPE 65307
00031 #define SCI_VK_CLEAR 65408
00032 #define SCI_VK_LEFT 65361
00033 #define SCI_VK_F1 65470
00034 
00035 /*-----------------------------------------------------------------------------------*/
00036 BOOL IsASpecialKey(UINT vk);
00037 UINT GetScilabSpecialKeyCode(UINT vk);
00038 BOOL is_dead_key (int vk); 
00039 /*-----------------------------------------------------------------------------------*/
00040 /* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/WindowsUserInterface/UserInput/VirtualKeyCodes.asp */
00041 /*-----------------------------------------------------------------------------------*/
00042 void ON_EVENT_GRAPH_WM_KEYUP(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
00043 {
00044         if ( is_dead_key (vk) )
00045         {
00046                 // Nothing to do
00047         }
00048         else
00049         {
00050                 if (IsASpecialKey(vk))
00051                 {
00052                         struct BCG *ScilabGC = (struct BCG *) GetWindowLong (hwnd, 0);
00053                         int x,y,iwin;
00054                         check_pointer_win(&x,&y,&iwin);
00055                         PushClickQueue (ScilabGC->CurWindow, x,y,-(int)GetScilabSpecialKeyCode(vk),0,1);
00056                 }
00057                 else
00058                 {
00059                         WORD Char=0;
00060                         BYTE KeyState[256]; // Etat des 256 touches du clavier 
00061                         memset ( KeyState, 0, sizeof(KeyState) ); 
00062                         if ( GetKeyboardState ( KeyState ) ) 
00063                         {
00064                                 int RetToAscii=0;
00065                                 int x,y,iwin;
00066                                 struct BCG *ScilabGC = (struct BCG *) GetWindowLong (hwnd, 0);
00067                                 int CodeKey=0;
00068 
00069                                 RetToAscii=ToAscii ( (UINT) vk,MapVirtualKey(vk, 0), KeyState, &Char, 0 );
00070                                 if (RetToAscii)
00071                                 {
00072                                         if (GetKeyState (VK_CONTROL) < 0)
00073                                         {
00074                                                 if ((Char>=1) && (Char<=29))
00075                                                 {
00076                                                         CodeKey=('a'-1+Char)+CTRL_KEY;
00077                                                 }
00078                                         }
00079                                         else CodeKey=Char;
00080 
00081                                         check_pointer_win(&x,&y,&iwin);
00082                                         PushClickQueue (ScilabGC->CurWindow, x,y,-(int)CodeKey,0,1);
00083                                 }
00084                         }
00085                 }
00086         }
00087 }
00088 /*-----------------------------------------------------------------------------------*/
00089 void ON_EVENT_GRAPH_WM_KEYDOWN(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
00090 {
00091         if ( is_dead_key (vk) )
00092         {
00093                 // Nothing to do
00094         }
00095         else
00096         {
00097                 if (IsASpecialKey(vk))
00098                 {
00099                         struct BCG *ScilabGC = (struct BCG *) GetWindowLong (hwnd, 0);
00100                         int x,y,iwin;
00101                         check_pointer_win(&x,&y,&iwin);
00102                         PushClickQueue (ScilabGC->CurWindow, x,y,(int)GetScilabSpecialKeyCode(vk),0,0);
00103                 }
00104                 else
00105                 {
00106                         WORD Char=0;
00107                         BYTE KeyState[256]; // Etat des 256 touches du clavier 
00108                         memset ( KeyState, 0, sizeof(KeyState) ); 
00109                         if ( GetKeyboardState ( KeyState ) ) 
00110                         {
00111                                 int RetToAscii=0;
00112                                 int x,y,iwin;
00113                                 struct BCG *ScilabGC = (struct BCG *) GetWindowLong (hwnd, 0);
00114                                 int CodeKey=0;
00115 
00116                                 RetToAscii=ToAscii ( (UINT) vk,MapVirtualKey(vk, 0), KeyState, &Char, 0 );
00117                                 if (RetToAscii)
00118                                 {
00119                                         if (GetKeyState (VK_CONTROL) < 0)
00120                                         {
00121                                                 if ((Char>=1) && (Char<=29))
00122                                                 {
00123                                                         CodeKey=('a'-1+Char)+CTRL_KEY;
00124                                                 }
00125                                         }
00126                                         else CodeKey=Char;
00127 
00128                                         check_pointer_win(&x,&y,&iwin);
00129                                         PushClickQueue (ScilabGC->CurWindow, x,y,(int)CodeKey,0,0);
00130                                 }
00131                         }
00132                 }
00133         }
00134 }
00135 /*-----------------------------------------------------------------------------------*/
00136 BOOL IsASpecialKey(UINT vk)
00137 {
00138         BOOL bOK=FALSE;
00139 
00140         if (vk == VK_CANCEL) return TRUE;
00141         if (vk == VK_PAUSE) return TRUE;
00142         if (vk == VK_SLEEP) return TRUE;
00143         if (vk == VK_INSERT) return TRUE;
00144         if (vk == VK_DELETE) return TRUE;
00145         if (vk == VK_END) return TRUE;
00146         if (vk == VK_HOME) return TRUE;
00147         if (vk == VK_PRIOR) return TRUE;
00148         if (vk == VK_NEXT) return TRUE;
00149         if (vk == VK_BACK) return TRUE;
00150         if (vk == VK_NUMLOCK) return TRUE;
00151         if (vk == VK_SCROLL) return TRUE;
00152         if (vk == VK_TAB) return TRUE;
00153         if (vk == VK_ESCAPE ) return TRUE;
00154         if (vk == VK_SNAPSHOT ) return TRUE;
00155         if (vk == VK_CLEAR ) return TRUE;
00156         if ( (vk>=VK_LEFT) && (vk<=VK_DOWN) ) return TRUE;
00157         if ( (vk>=VK_F1) && (vk<=VK_F24) ) return TRUE;
00158 
00159         return FALSE;
00160 }
00161 /*-----------------------------------------------------------------------------------*/
00162 UINT GetScilabSpecialKeyCode(UINT vk)
00163 {
00164         UINT ScilabSpecialKeyCode=0;
00165 
00166         if (vk == VK_CANCEL)  ScilabSpecialKeyCode=SCI_VK_CANCEL;
00167         if (vk == VK_PAUSE)  ScilabSpecialKeyCode=SCI_VK_PAUSE;
00168         if (vk == VK_SLEEP)  ScilabSpecialKeyCode=SCI_VK_SLEEP; 
00169         if (vk == VK_INSERT) ScilabSpecialKeyCode=SCI_VK_INSERT;
00170         if (vk == VK_DELETE) ScilabSpecialKeyCode=SCI_VK_DELETE;
00171         if (vk == VK_END)  ScilabSpecialKeyCode=SCI_VK_END;
00172         if (vk == VK_HOME)  ScilabSpecialKeyCode=SCI_VK_HOME;
00173         if (vk == VK_PRIOR)  ScilabSpecialKeyCode=SCI_VK_PRIOR;
00174         if (vk == VK_NEXT)  ScilabSpecialKeyCode=SCI_VK_NEXT;
00175         if (vk == VK_BACK)  ScilabSpecialKeyCode=SCI_VK_BACK;
00176         if (vk == VK_NUMLOCK)  ScilabSpecialKeyCode=SCI_VK_NUMLOCK; 
00177         if (vk == VK_SCROLL)  ScilabSpecialKeyCode=SCI_VK_SCROLL; 
00178         if (vk == VK_SNAPSHOT ) ScilabSpecialKeyCode=SCI_VK_SNAPSHOT;
00179         if (vk == VK_TAB)   ScilabSpecialKeyCode=SCI_VK_TAB;
00180         if (vk ==  VK_ESCAPE ) ScilabSpecialKeyCode=SCI_VK_ESCAPE;
00181   if (vk == VK_CLEAR ) ScilabSpecialKeyCode=SCI_VK_CLEAR;
00182         if ( (vk>=VK_LEFT) && (vk<=VK_DOWN) )  ScilabSpecialKeyCode= (SCI_VK_LEFT-VK_LEFT)+vk;
00183         if ( (vk>=VK_F1) && (vk<=VK_F24) )  ScilabSpecialKeyCode= (SCI_VK_F1-VK_F1)+vk;
00184 
00185         return ScilabSpecialKeyCode;
00186 }
00187 /*-----------------------------------------------------------------------------------*/
00188 BOOL is_dead_key (int vk) 
00189 { 
00190         unsigned int code = MapVirtualKey ( vk, 2 ); 
00191 
00192         // Windows 95 retourne 0x8000, NT retourne 0x80000000 
00193         return (code & 0x80008000) ? TRUE : FALSE; 
00194 } 
00195 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:54 2007 for Scilab [trunk] by  doxygen 1.5.1