Mostly minor fixes up until version 0.8.10.
[irreco.git] / irtrans / irserver / src / mce.c
blobc9fd26305b454f4f8e5b39003af5f700670c0fcc
1 /*
2 * Copyright (c) 2007, IRTrans GmbH
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of IRTrans GmbH nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY IRTrans GmbH ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL IRTrans GmbH BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifdef WIN32
32 #define _WIN32_WINNT 0x501
34 #include <windows.h>
35 #include <winuser.h>
36 #include <io.h>
37 #include <direct.h>
38 #include <stdio.h>
39 #include <sys/timeb.h>
42 #include "remote.h"
43 #include "global.h"
44 #include "lowlevel.h"
45 #include "dbstruct.h"
47 #endif
49 HMODULE kdll;
52 #ifdef MEDIACENTER
54 extern DEVICEINFO IRDevices[MAX_IR_DEVICES];
55 extern APP app_pnt[30];
56 extern int app_cnt;
58 void SendMediaCenterAction (int app,int com);
59 void IRTransSendInput (int key,int flags);
60 void SendKey (APP *app,APPCOMMAND *appcom,byte flag);
61 void ConvertLcase (char *pnt,int len);
62 void SendMediacenterEvent (int eventcode);
63 void SendAppcommand (APP *app,APPCOMMAND *appcom);
64 void SendWMChar (APP *app,APPCOMMAND *appcom);
65 void HandleKeyboardScancodes (char scan[]);
66 void HandleDirectScancodes (char scan[]);
67 void HandleMouse (char mov[]);
68 //------------------------------------------modified------------------------------------------
69 void HandleShortcut (char shortcut[]);
73 unsigned int GetFineTime (void);
76 #define CONTROL 1
77 #define SHIFT 2
78 #define NO_KEYUP 4
79 #define ALT 8
80 #define LWINKEY 16
82 //#define MULTIKEY_TIMEOUT 1000
83 //------------------------------------------modified------------------------------------------
84 #define MULTIKEY_TIMEOUT 500
87 #define SCAN_SHIFT 1
88 #define SCAN_CTRL 2
89 #define SCAN_ALT 4
90 #define SCAN_WIN 8
92 #define SC_ALTGR 1
93 #define SC_SHIFT_R 2
94 #define SC_CTRL_R 4
95 #define SC_WIN_R 8
96 #define SC_ALT 16
97 #define SC_SHIFT_L 32
98 #define SC_CTRL_L 64
101 void PostWindowsMessage (int rem,int com,char name[])
103 int i,j;
104 APPCOMMAND *appcom;
105 for (i=0;i < app_cnt;i++) if (app_pnt[i].remnum == rem) {
106 if (app_pnt[i].type == TYPE_KEYBOARD) HandleKeyboardScancodes (name);
107 else if (app_pnt[i].type == TYPE_SCANCODE) HandleDirectScancodes (name);
108 else if (app_pnt[i].type == TYPE_MOUSE) HandleMouse (name);
109 //------------------------------------------modified------------------------------------------
110 else if (app_pnt[i].type == TYPE_SHORTCUT) HandleShortcut (name);
113 else for (j=0;j < app_pnt[i].com_cnt;j++) if (app_pnt[i].com[j].comnum == com) {
114 appcom = &(app_pnt[i].com[j]);
115 if (appcom->type[0] == TYPE_MCE) SendMediaCenterAction (i,j);
116 if (appcom->type[0] == TYPE_KEY) SendKey (app_pnt + i,appcom,0);
117 if (appcom->type[0] == TYPE_KEYF) SendKey (app_pnt + i,appcom,1);
118 if (appcom->type[0] == TYPE_APPCOM) SendAppcommand (app_pnt + i,appcom);
119 if (appcom->type[0] == TYPE_CHR) SendWMChar (app_pnt + i,appcom);
124 //------------------------------------------modified------------------------------------------
125 void HandleShortcut (char shortcut[])
127 ShellExecute(NULL,"open",shortcut,NULL,NULL,SW_SHOWNORMAL ); //execute shortcut in remotes folder
131 void HandleMouse (char mov[])
133 static byte last_m1,last_m2;
135 byte m1,m2;
136 INPUT InpInfo[20];
137 int x,y,p = 0;
139 m1 = mov[9] - '0';
140 m2 = mov[8] - '0';
141 x = atoi (mov);
142 y = atoi (mov + 4);
144 p = 0;
145 memset (InpInfo,0,sizeof (InpInfo));
147 if (last_m1 != m1) {
148 InpInfo[p].type = INPUT_MOUSE;
149 if (m1) InpInfo[p].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
150 else InpInfo[p].mi.dwFlags = MOUSEEVENTF_LEFTUP;
151 p++;
153 if (last_m2 != m2) {
154 InpInfo[p].type = INPUT_MOUSE;
155 if (m1) InpInfo[p].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
156 else InpInfo[p].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
157 p++;
160 if (x || y) {
161 InpInfo[p].type = INPUT_MOUSE;
162 InpInfo[p].mi.dx = x;
163 InpInfo[p].mi.dy = y;
164 InpInfo[p].mi.dwFlags = MOUSEEVENTF_MOVE;
165 p++;
168 if (p) SendInput (p,InpInfo,sizeof (INPUT));
170 last_m1 = m1;
171 last_m2 = m2;
174 void HandleDirectScancodes (char scan[])
176 static byte last_scan;
177 static byte last_flags;
178 static unsigned int last_time;
180 HKL layout;
181 INPUT InpInfo[20];
182 int p,key;
184 byte chr;
185 byte scancode;
186 byte flags;
188 chr = scan[0];
189 if (chr >= 'a' && chr <= 'f') chr = chr - 'a' + 10;
190 else chr -= '0';
192 scancode = chr;
194 chr = scan[1];
195 if (chr >= 'a' && chr <= 'f') chr = chr - 'a' + 10;
196 else chr -= '0';
197 scancode = scancode * 16 + chr;
199 p = 2;
200 flags = 0;
201 key = 1;
203 while (p <= 8) {
204 if (scan[p] == '1') flags |= key;
205 p++;
206 key <<= 1;
209 if (flags & SC_ALTGR) flags |= SC_ALT | SC_CTRL_L;
211 if (last_scan == scancode && last_flags != flags && (GetFineTime () - last_time) < 250) return;
213 layout = GetKeyboardLayout (0);
215 if (scancode == VK_APPS) key = VK_APPS;
216 else key = MapVirtualKeyEx (scancode,1,layout);
219 memset (InpInfo,0,sizeof (InpInfo));
221 p = 0;
222 if (flags & SC_SHIFT_L) {
223 InpInfo[p].type = INPUT_KEYBOARD;
224 InpInfo[p].ki.wVk = VK_LSHIFT;
225 p++;
227 if (flags & SC_SHIFT_R) {
228 InpInfo[p].type = INPUT_KEYBOARD;
229 InpInfo[p].ki.wVk = VK_RSHIFT;
230 p++;
232 if (flags & SC_CTRL_L) {
233 InpInfo[p].type = INPUT_KEYBOARD;
234 InpInfo[p].ki.wVk = VK_LCONTROL;
235 p++;
237 if (flags & SC_CTRL_R) {
238 InpInfo[p].type = INPUT_KEYBOARD;
239 InpInfo[p].ki.wVk = VK_RCONTROL;
240 p++;
242 if (flags & SC_ALT) {
243 InpInfo[p].type = INPUT_KEYBOARD;
244 InpInfo[p].ki.wVk = VK_MENU;
245 p++;
247 if (flags & SC_WIN_R) {
248 InpInfo[p].type = INPUT_KEYBOARD;
249 InpInfo[p].ki.wVk = VK_LWIN;
250 p++;
253 if (key) {
254 InpInfo[p].type = INPUT_KEYBOARD;
255 InpInfo[p].ki.wVk = key;
256 p++;
258 InpInfo[p].type = INPUT_KEYBOARD;
259 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
260 InpInfo[p].ki.wVk = key;
261 p++;
264 if (flags & SC_WIN_R) {
265 InpInfo[p].type = INPUT_KEYBOARD;
266 InpInfo[p].ki.wVk = VK_LWIN;
267 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
268 p++;
270 if (flags & SC_ALT) {
271 InpInfo[p].type = INPUT_KEYBOARD;
272 InpInfo[p].ki.wVk = VK_MENU;
273 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
274 p++;
276 if (flags & SC_CTRL_R) {
277 InpInfo[p].type = INPUT_KEYBOARD;
278 InpInfo[p].ki.wVk = VK_RCONTROL;
279 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
280 p++;
282 if (flags & SC_CTRL_L) {
283 InpInfo[p].type = INPUT_KEYBOARD;
284 InpInfo[p].ki.wVk = VK_LCONTROL;
285 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
286 p++;
288 if (flags & SC_SHIFT_R) {
289 InpInfo[p].type = INPUT_KEYBOARD;
290 InpInfo[p].ki.wVk = VK_RSHIFT;
291 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
292 p++;
294 if (flags & SC_SHIFT_L) {
295 InpInfo[p].type = INPUT_KEYBOARD;
296 InpInfo[p].ki.wVk = VK_LSHIFT;
297 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
298 p++;
300 SendInput (p,InpInfo,sizeof (INPUT));
302 last_scan = scancode;
303 last_flags = flags;
304 last_time = GetFineTime ();
308 void HandleKeyboardScancodes (char scan[])
310 static byte last_scan;
311 static byte last_flags;
312 static unsigned int last_time;
314 HKL layout;
315 INPUT InpInfo[10];
316 int p,key;
318 byte chr;
319 byte scancode;
320 byte flags;
322 chr = scan[0];
323 if (chr >= 'a' && chr <= 'f') chr = chr - 'a' + 10;
324 else chr -= '0';
326 scancode = chr;
328 chr = scan[1];
329 if (chr >= 'a' && chr <= 'f') chr = chr - 'a' + 10;
330 else chr -= '0';
331 scancode = scancode * 16 + chr;
333 flags = scan[2] - '0';
335 if (last_scan == scancode && last_flags != flags && (GetFineTime () - last_time) < 250) return;
337 layout = GetKeyboardLayout (0);
339 if (scancode == VK_APPS) key = VK_APPS;
340 else key = MapVirtualKeyEx (scancode,1,layout);
343 memset (InpInfo,0,sizeof (InpInfo));
345 p = 0;
346 if (flags & SCAN_CTRL) {
347 InpInfo[p].type = INPUT_KEYBOARD;
348 InpInfo[p].ki.wVk = VK_CONTROL;
349 p++;
351 if (flags & SCAN_SHIFT) {
352 InpInfo[p].type = INPUT_KEYBOARD;
353 InpInfo[p].ki.wVk = VK_SHIFT;
354 p++;
356 if (flags & SCAN_ALT) {
357 InpInfo[p].type = INPUT_KEYBOARD;
358 InpInfo[p].ki.wVk = VK_MENU;
359 p++;
361 if (flags & SCAN_WIN) {
362 InpInfo[p].type = INPUT_KEYBOARD;
363 InpInfo[p].ki.wVk = VK_LWIN;
364 p++;
367 if (key) {
368 InpInfo[p].type = INPUT_KEYBOARD;
369 InpInfo[p].ki.wVk = key;
370 p++;
372 InpInfo[p].type = INPUT_KEYBOARD;
373 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
374 InpInfo[p].ki.wVk = key;
375 p++;
378 if (flags & SCAN_WIN) {
379 InpInfo[p].type = INPUT_KEYBOARD;
380 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
381 InpInfo[p].ki.wVk = VK_LWIN;
382 p++;
384 if (flags & SCAN_ALT) {
385 InpInfo[p].type = INPUT_KEYBOARD;
386 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
387 InpInfo[p].ki.wVk = VK_MENU;
388 p++;
390 if (flags & SCAN_SHIFT) {
391 InpInfo[p].type = INPUT_KEYBOARD;
392 InpInfo[p].ki.wVk = VK_SHIFT;
393 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
394 p++;
396 if (flags & SCAN_CTRL) {
397 InpInfo[p].type = INPUT_KEYBOARD;
398 InpInfo[p].ki.wVk = VK_CONTROL;
399 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
400 p++;
402 SendInput (p,InpInfo,sizeof (INPUT));
404 last_scan = scancode;
405 last_flags = flags;
406 last_time = GetFineTime ();
410 void SendWMChar (APP *app,APPCOMMAND *appcom)
412 HWND win;
414 win = FindWindow (app->classname,NULL);
415 if (!win) return;
417 PostMessage (win,WM_KEYDOWN,(WPARAM)appcom->function[0],(LPARAM)0);
418 // PostMessage (win,WM_KEYUP,(WPARAM)appcom->function[0],(LPARAM)0xC0000001);
421 void SendAppcommand (APP *app,APPCOMMAND *appcom)
423 HWND win;
425 win = FindWindow (app->classname,NULL);
426 if (!win) return;
428 PostMessage (win,WM_APPCOMMAND,(WPARAM)1,(LPARAM)(appcom->function[0] << 16));
431 void SendKey (APP *app,APPCOMMAND *appcom,byte flag)
433 HWND win;
434 DWORD thr;
435 byte mf = 0;
436 struct _timeb tb;
437 unsigned int tv;
439 static byte cindex;
440 static APPCOMMAND *lastcom;
441 static unsigned int lasttime;
443 if (app && app->classname[0]) {
444 win = FindWindow (app->classname,NULL);
445 if (!win) return;
446 if (flag) {
447 thr = GetWindowThreadProcessId (win,NULL);
448 AttachThreadInput (GetCurrentThreadId (),thr,TRUE);
450 SetFocus (win);
452 AttachThreadInput (GetCurrentThreadId (),thr,FALSE);
456 _ftime (&tb);
457 tv = (unsigned int)((tb.time & 0x7fffff) * 1000 + tb.millitm);
459 if (appcom != lastcom) cindex = 0;
460 else {
461 if ((tv - lasttime) < MULTIKEY_TIMEOUT) mf = ++cindex;
462 else cindex = 0;
465 if (appcom->type[cindex] != TYPE_KEY) {
466 if (cindex == 1) mf = 0;
467 cindex = 0;
470 // if (mf) IRTransSendInput (VK_BACK,0);
471 //------------------------------------------modified------------------------------------------
472 //send (backspace + left winkey) to delete letters as it has no effect when changing channels,
473 //and backspace is used to switch to the previous scren in MCE and
474 if (mf != 0)
476 IRTransSendInput (VK_BACK,LWINKEY);
479 IRTransSendInput (appcom->function[cindex] & 0xff,(appcom->function[cindex] & 0xff00) >> 8);
481 lastcom = appcom;
482 lasttime = tv;
485 void SendMediaCenterAction (int app,int com)
487 int res;
488 HWND mcewin;
489 char *sysdir,prog[256];
491 mcewin = FindWindow (app_pnt[app].classname,NULL);
492 if (mcewin == NULL) {
493 if (app_pnt[app].com[com].type[0] == TYPE_RUN || app_pnt[app].com[com].type[1] == TYPE_RUN) {
494 sysdir = getenv ("SystemRoot");
495 if (sysdir) {
496 sprintf (prog,"%s\\ehome\\ehshell.exe",sysdir);
497 if (app_pnt[app].com[com].function[0] == 40) strcat (prog," /homepage:VideoCollection.xml /pushstartpage:true"); // Video
498 if (app_pnt[app].com[com].function[0] == 35) strcat (prog," /homepage:Audio.Home.xml /pushstartpage:true"); // Music
499 if (app_pnt[app].com[com].function[0] == 39) strcat (prog," /homepage:VideoHome.xml /pushstartpage:true"); // TV
500 if (app_pnt[app].com[com].function[0] == 45) strcat (prog," /homepage:Radio.xml /pushstartpage:true"); // Radio
501 if (app_pnt[app].com[com].function[0] == 36) strcat (prog," /homepage:Photos.xml /pushstartpage:true"); // Pictures
502 if (app_pnt[app].com[com].function[0] == 37) strcat (prog," /homepage:VideoRecordedPrograms.xml /pushstartpage:true"); // RecTV
503 res = WinExec (prog,SW_SHOWMAXIMIZED);
506 else if (app_pnt[app].com[com].function[0] == 42) IRTransSendInput (VK_RETURN,ALT | LWINKEY);
508 else {
509 switch (app_pnt[app].com[com].function[0]) {
510 case 12: // Clear
511 IRTransSendInput (VK_ESCAPE,0);
512 return;
513 case 17: // Mute
514 // IRTransSendInput (119,0);
515 SendMediacenterEvent (APPCOMMAND_VOLUME_MUTE);
516 return;
517 case 18: // Vol-
518 // IRTransSendInput (120,0);
519 SendMediacenterEvent (APPCOMMAND_VOLUME_DOWN);
520 return;
521 case 19: // Vol+
522 // IRTransSendInput (121,0);
523 SendMediacenterEvent (APPCOMMAND_VOLUME_UP);
524 return;
525 case 20: // Play
526 // IRTransSendInput (80,SHIFT | CONTROL);
527 SendMediacenterEvent (APPCOMMAND_MEDIA_PLAY);
528 return;
529 case 21: // Stop
530 // IRTransSendInput (83,SHIFT | CONTROL);
531 SendMediacenterEvent (APPCOMMAND_MEDIA_STOP);
532 return;
533 case 22: // Next
534 // IRTransSendInput (70,CONTROL);
535 SendMediacenterEvent (APPCOMMAND_MEDIA_NEXTTRACK);
536 return;
537 case 23: // Prev
538 // IRTransSendInput (66,CONTROL);
539 SendMediacenterEvent (APPCOMMAND_MEDIA_PREVIOUSTRACK);
540 return;
541 case 24: // REC
542 // IRTransSendInput (82,CONTROL);
543 SendMediacenterEvent (APPCOMMAND_MEDIA_RECORD);
544 return;
545 case 25: // Pause
546 // IRTransSendInput (80,CONTROL);
547 SendMediacenterEvent (APPCOMMAND_MEDIA_PAUSE);
548 return;
549 case 26: // REW
550 // IRTransSendInput (66,SHIFT | CONTROL);
551 SendMediacenterEvent (APPCOMMAND_MEDIA_REWIND);
552 return;
553 case 27: // FWD
554 // IRTransSendInput (70,SHIFT | CONTROL);
555 SendMediacenterEvent (APPCOMMAND_MEDIA_FAST_FORWARD);
556 return;
557 case 28: // Ch+
558 IRTransSendInput (187,CONTROL);
559 // SendMediacenterEvent (APPCOMMAND_MEDIA_CHANNEL_UP);
560 return;
561 case 29: // Ch-
562 IRTransSendInput (189,CONTROL);
563 // SendMediacenterEvent (APPCOMMAND_MEDIA_CHANNEL_DOWN);
564 return;
565 case 31: // DVDMenu
566 IRTransSendInput (77,SHIFT | CONTROL);
567 return;
568 case 32: // DVDAudio
569 IRTransSendInput (65,SHIFT | CONTROL);
570 return;
571 case 33: // DVDSubtitle
572 IRTransSendInput (85,SHIFT | CONTROL);
573 return;
574 case 34: // EPG
575 IRTransSendInput (71,CONTROL);
576 return;
577 case 35: // Music
578 IRTransSendInput (77,CONTROL);
579 return;
580 case 36: // Pictures
581 IRTransSendInput (73,CONTROL);
582 return;
583 case 37: // RecTV
584 IRTransSendInput (79,CONTROL);
585 return;
586 case 38: // TV
587 IRTransSendInput (84,CONTROL | SHIFT);
588 return;
589 case 39: // LiveTV
590 IRTransSendInput (84,CONTROL);
591 return;
592 case 40: // Video
593 IRTransSendInput (69,CONTROL);
594 return;
595 case 41: // Info
596 IRTransSendInput (68,CONTROL);
597 return;
598 case 42: // Ehome
599 IRTransSendInput (VK_RETURN,ALT | LWINKEY);
600 return;
601 case 43: // Messenger
602 IRTransSendInput (78,CONTROL);
603 return;
604 case 44: // Teletext
605 IRTransSendInput (68,CONTROL);
606 return;
607 case 45: // Radio
608 IRTransSendInput (65,CONTROL);
609 return;
610 case 46: // Back
611 SendMediacenterEvent (APPCOMMAND_BROWSER_BACKWARD);
612 return;
618 void SendMediacenterEvent (int eventcode)
620 HWND mcewin;
622 mcewin = FindWindow ("eHome Render Window",NULL);
623 if (!mcewin) return;
624 PostMessage (mcewin,WM_APPCOMMAND,(WPARAM)1,(LPARAM)(eventcode << 16));
628 int GetKeyCode (char *com)
630 int key = 0;
631 if (*com == '\\') {
632 com++;
633 if (!strcmp (com,"space")) return ' ';
634 if (!strcmp (com,"enter")) return VK_RETURN;
635 if (!strcmp (com,"up")) return VK_UP;
636 if (!strcmp (com,"down")) return VK_DOWN;
637 if (!strcmp (com,"right")) return VK_RIGHT;
638 if (!strcmp (com,"left")) return VK_LEFT;
639 if (!strcmp (com,"backspace")) return VK_BACK;
640 if (!strcmp (com,"end")) return VK_END;
641 if (!strcmp (com,"home")) return VK_HOME;
642 if (!strcmp (com,"pgup")) return VK_PRIOR;
643 if (!strcmp (com,"pgdown")) return VK_NEXT;
644 if (!strcmp (com,"esc")) return VK_ESCAPE;
645 if (!strcmp (com,"tab")) return VK_TAB;
646 if (!strcmp (com,"f1")) return VK_F1;
647 if (!strcmp (com,"f2")) return VK_F2;
648 if (!strcmp (com,"f3")) return VK_F3;
649 if (!strcmp (com,"f4")) return VK_F4;
650 if (!strcmp (com,"f5")) return VK_F5;
651 if (!strcmp (com,"f6")) return VK_F6;
652 if (!strcmp (com,"f7")) return VK_F7;
653 if (!strcmp (com,"f8")) return VK_F8;
654 if (!strcmp (com,"f9")) return VK_F9;
655 if (!strcmp (com,"f10")) return VK_F10;
656 if (!strcmp (com,"f11")) return VK_F11;
657 if (!strcmp (com,"f12")) return VK_F12;
658 while (!strncmp (com,"alt",3) || !strncmp (com,"ctrl",4) || !strncmp (com,"shift",5)) {
659 if (!strncmp (com,"alt",3)) {
660 key |= ALT << 8;
661 com += 3;
663 if (!strncmp (com,"ctrl",4)) {
664 key |= CONTROL << 8;
665 com += 4;
667 if (!strncmp (com,"shift",5)) {
668 key |= SHIFT << 8;
669 com += 5;
671 if (*com == 0) return (0);
673 if (*com == '\\') com++;
674 else return (key | *com);
677 return (0);
679 if (*com >= 'a' && *com <= 'z') return (*com - ('a' - 'A'));
680 else return (*com);
683 int GetFunctionCode (byte type,char *com)
685 if (type == TYPE_APPCOM) {
686 if (!strcmp (com,"appcommand_media_play")) return APPCOMMAND_MEDIA_PLAY;
687 if (!strcmp (com,"appcommand_volume_mute")) return APPCOMMAND_VOLUME_MUTE;
688 if (!strcmp (com,"appcommand_volume_down")) return APPCOMMAND_VOLUME_DOWN;
689 if (!strcmp (com,"appcommand_volume_up")) return APPCOMMAND_VOLUME_UP;
690 if (!strcmp (com,"appcommand_media_stop")) return APPCOMMAND_MEDIA_STOP;
691 if (!strcmp (com,"appcommand_media_nexttrack")) return APPCOMMAND_MEDIA_NEXTTRACK;
692 if (!strcmp (com,"appcommand_media_previoustrack")) return APPCOMMAND_MEDIA_PREVIOUSTRACK;
693 if (!strcmp (com,"appcommand_media_record")) return APPCOMMAND_MEDIA_RECORD;
694 if (!strcmp (com,"appcommand_media_pause")) return APPCOMMAND_MEDIA_PAUSE;
695 if (!strcmp (com,"appcommand_media_rewind")) return APPCOMMAND_MEDIA_REWIND;
696 if (!strcmp (com,"appcommand_media_fast_forward")) return APPCOMMAND_MEDIA_FAST_FORWARD;
697 if (!strcmp (com,"appcommand_browser_backward")) return APPCOMMAND_BROWSER_BACKWARD;
700 else if (type == TYPE_MCE) {
701 if (!strcmp (com,"clear")) return 12;
702 if (!strcmp (com,"mute")) return 17;
703 if (!strcmp (com,"vol-")) return 18;
704 if (!strcmp (com,"vol+")) return 19;
705 if (!strcmp (com,"play")) return 20;
706 if (!strcmp (com,"stop")) return 21;
707 if (!strcmp (com,"next")) return 22;
708 if (!strcmp (com,"prev")) return 23;
709 if (!strcmp (com,"rec")) return 24;
710 if (!strcmp (com,"pause")) return 25;
711 if (!strcmp (com,"rew")) return 26;
712 if (!strcmp (com,"fwd")) return 27;
713 if (!strcmp (com,"ch+")) return 28;
714 if (!strcmp (com,"ch-")) return 29;
715 if (!strcmp (com,"dvdmenu")) return 31;
716 if (!strcmp (com,"dvdaudio")) return 32;
717 if (!strcmp (com,"dvdsubtitle")) return 33;
718 if (!strcmp (com,"epg")) return 34;
719 if (!strcmp (com,"music")) return 35;
720 if (!strcmp (com,"pictures")) return 36;
721 if (!strcmp (com,"rectv")) return 37;
722 if (!strcmp (com,"tv")) return 38;
723 if (!strcmp (com,"livetv")) return 39;
724 if (!strcmp (com,"video")) return 40;
725 if (!strcmp (com,"info")) return 41;
726 if (!strcmp (com,"ehome")) return 42;
727 if (!strcmp (com,"messenger")) return 43;
728 if (!strcmp (com,"teletext")) return 44;
729 if (!strcmp (com,"radio")) return 45;
730 if (!strcmp (com,"back")) return 46;
731 return 0;
733 return 0;
737 //typedef BOOL (WINAPI *PtrKbdSim)(KBDSIM_INPUT_DATA *);
738 //PtrKbdSim m_KbdSim = 0;
741 int InitInput ()
743 char msg[255];
745 kdll = LoadLibrary("kbdsim.dll");
746 if(kdll == NULL)
748 sprintf (msg,"Error: Can't Load kbdsim.dll\n");
749 log_print (msg,LOG_FATAL);
750 return (-1);
753 m_KbdSim = (PtrKbdSim)GetProcAddress(kdll, "KbdSimSendInput");
754 return (0);
757 BOOL WINAPI KbdSimSendInput(KBDSIM_INPUT_DATA *pInput)
759 return (*m_KbdSim)(pInput);
763 void IRTransSendInput (int key,int flags)
765 // KBDSIM_INPUT_DATA Input;
766 INPUT InpInfo[10];
767 int p;
770 if (m_KbdSim) {
772 if (flags & CONTROL) {
773 Input.UnitId = 0; // Keyboard 0
774 Input.MakeCode = 29; // Scancode for CTRL
775 Input.Flags = 0; // Key down
776 Input.Reserved = 0;
777 Input.ExtraInformation = 0;
778 KbdSimSendInput(&Input);
781 if (key == 'm') {
783 Input.UnitId = 0; // Keyboard 0
784 Input.MakeCode = 50; // Scancode for '1'
785 Input.Flags = 0; // Key down
786 Input.Reserved = 0;
787 Input.ExtraInformation = 0;
789 KbdSimSendInput(&Input);
791 Input.UnitId = 0; // Keyboard 0
792 Input.MakeCode = 50; // Scancode for '1'
793 Input.Flags = 1; // Key up
794 Input.Reserved = 0;
795 Input.ExtraInformation = 0;
797 KbdSimSendInput(&Input);
800 Input.UnitId = 0; // Keyboard 0
801 Input.MakeCode = 29; // Scancode for '1'
802 Input.Flags = 1; // Key up
803 Input.Reserved = 0;
804 Input.ExtraInformation = 0;
806 KbdSimSendInput(&Input);
808 return;
812 if (key == '1') {
813 Input.UnitId = 0; // Keyboard 0
814 Input.MakeCode = 2; // Scancode for '1'
815 Input.Flags = 0; // Key down
816 Input.Reserved = 0;
817 Input.ExtraInformation = 0;
819 KbdSimSendInput(&Input);
821 Input.UnitId = 0; // Keyboard 0
822 Input.MakeCode = 2; // Scancode for '1'
823 Input.Flags = 1; // Key up
824 Input.Reserved = 0;
825 Input.ExtraInformation = 0;
827 KbdSimSendInput(&Input);
829 return;
832 return;
836 memset (InpInfo,0,sizeof (InpInfo));
838 p = 0;
839 if (flags & CONTROL) {
840 InpInfo[p].type = INPUT_KEYBOARD;
841 InpInfo[p].ki.wVk = VK_CONTROL;
842 p++;
844 if (flags & SHIFT) {
845 InpInfo[p].type = INPUT_KEYBOARD;
846 InpInfo[p].ki.wVk = VK_SHIFT;
847 p++;
849 if (flags & ALT) {
850 InpInfo[p].type = INPUT_KEYBOARD;
851 InpInfo[p].ki.wVk = VK_MENU;
852 p++;
854 if (flags & LWINKEY) {
855 InpInfo[p].type = INPUT_KEYBOARD;
856 InpInfo[p].ki.wVk = VK_LWIN;
857 p++;
861 InpInfo[p].type = INPUT_KEYBOARD;
862 InpInfo[p].ki.wVk = key;
863 p++;
865 if (!(flags & NO_KEYUP)) {
866 InpInfo[p].type = INPUT_KEYBOARD;
867 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
868 InpInfo[p].ki.wVk = key;
869 p++;
872 if (flags & LWINKEY) {
873 InpInfo[p].type = INPUT_KEYBOARD;
874 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
875 InpInfo[p].ki.wVk = VK_LWIN;
876 p++;
878 if (flags & ALT) {
879 InpInfo[p].type = INPUT_KEYBOARD;
880 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
881 InpInfo[p].ki.wVk = VK_MENU;
882 p++;
884 if (flags & SHIFT) {
885 InpInfo[p].type = INPUT_KEYBOARD;
886 InpInfo[p].ki.wVk = VK_SHIFT;
887 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
888 p++;
890 if (flags & CONTROL) {
891 InpInfo[p].type = INPUT_KEYBOARD;
892 InpInfo[p].ki.wVk = VK_CONTROL;
893 InpInfo[p].ki.dwFlags = KEYEVENTF_KEYUP;
894 p++;
896 SendInput (p,InpInfo,sizeof (INPUT));
899 #endif