The following script was made to intercept remote control keys from your WinFast PVR application.
If you have Leadtek TV card, or WinFast PVR application, and remote control, you might find this useful, you could turn your TV card remote control into ultimate, distant PC control device.
Please read the first few lines of the script, and choose first global variable, if you have WinFast PVR1, then use:
Global $class = "Alec@Video(^0^)"
if you have WinFast PVR2 or higher, then use:
Global $class = "Alec@DVBT(
Also, this script was made tnx to register class function: http://www.autoitscript.com/forum/index.php?showtopic=79575
AutoIt
#Include <WinAPI.au3> #Include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Constants.au3> ;choose the class which depends on your PVR you're using. PVR1 = "Alec@Video(^0^)", PVR2 and higher = "Alec@DVBT(^_^)" ;~ Global $class = "Alec@Video(^0^)" ;for pvr1 Global $class = "Alec@DVBT(^_^)" ;for pvr2 and up Global $enabled = true Global Const $CS_VREDRAW = 0x0001; Global Const $CS_HREDRAW = 0x0002; Global Const $CS_DBLCLKS = 0x0008; Global Const $CS_OWNDC = 0x0020; Global Const $CS_CLASSDC = 0x0040; Global Const $CS_PARENTDC = 0x0080; Global Const $CS_NOCLOSE = 0x0200; Global Const $CS_SAVEBITS = 0x0800; Global Const $CS_BYTEALIGNCLIENT = 0x1000; Global Const $CS_BYTEALIGNWINDOW = 0x2000; Global Const $CS_GLOBALCLASS = 0x4000; Global Const $CS_DROPSHADOW = 0x00020000; Global Const $CS_DEFAULTSTYLE = BitOR($CS_VREDRAW, $CS_HREDRAW) Global Const $CW_USEDEFAULT = 0x80000000 ;#CS Global Const $CURSOR_ARROW =32512 Global Const $CURSOR_IBEAM =32513 Global Const $CURSOR_WAIT =32514 Global Const $CURSOR_CROSS =32515 Global Const $CURSOR_UPARROW =32516 Global Const $CURSOR_SIZENWSE =32642 Global Const $CURSOR_SIZENESW =32643 Global Const $CURSOR_SIZEWE =32644 Global Const $CURSOR_SIZENS =32645 Global Const $CURSOR_SIZEALL =32646 Global Const $CURSOR_NO =32648 Global Const $CURSOR_APPSTARTING =32650 Global Const $CURSOR_HELP =32651 ;#CE _WinAPI_RegisterClassEx($class, "WindowCallback", 0, 0, -1, $CS_DEFAULTSTYLE) ;registering window class which is designed to recieve PVR's remote ctrl commands, and setting up a func. for hooking msges from that class (this last require a window, that's why we have next line) $hWnd = _WinAPI_CreateWindowEx(0, $class, "REMOTE CONTROL", $WS_OVERLAPPEDWINDOW, @DesktopWidth+500, @DesktopHeight+500, 0, 0, 0) ;creating a window with registered class (required, but doesn't need to be shown) $gui = GUICreate("test", 400, 300) ;creating main GUI $button1 = GUICtrlCreateButton("Disable", 10, 10, 100) ;button for disabling/enabling keys intercepting (actually, registering and unregistering required window's class $display_label = GUICtrlCreateLabel("", 10, 50, 380, 20, 0x01) ;label for displaying keys you stroke on your remote ctrl. GUICtrlSetFont(-1, 12, 800, -1, "Arial") GUISetState(@SW_SHOW) While 1 Local $nMsg = GUIGetMsg($gui) Switch $nMsg case $button1 if $enabled = true Then GUICtrlSetData($button1, "Enable") $enabled = false _WinAPI_UnregisterClass($class) ;unregistering class and... _WinAPI_DestroyWindow($hWnd) ;...killing window with registered class $hWnd = 0 Else GUICtrlSetData($button1, "Disable") $enabled = true _WinAPI_RegisterClassEx($class, "WindowCallback", 0, 0, -1, $CS_DEFAULTSTYLE) ;just like @ the top of the script $hWnd = _WinAPI_CreateWindowEx(0, $class, "REMOTE CONTROL", $WS_OVERLAPPEDWINDOW, @DesktopWidth+500, @DesktopHeight+500, 0, 0, 0) EndIf Case $GUI_EVENT_CLOSE _WinAPI_UnregisterClass($class) Exit EndSwitch Sleep(10) WEnd Func _WinGetClassName($hWnd) $x = DLLCall("user32.dll","int","GetClassName","hWnd",$hWnd,"str","","int",64) ;getting classname of a window If Not @error And $x[0] <> 0 Then Return $x[2] Return "" EndFunc Func WindowCallback($hWnd, $iMsg, $wParam, $lParam) ;callback func. for recieving msges Switch $iMsg Case $WM_CLOSE _WinAPI_UnregisterClass($class) Exit EndSwitch Switch $wParam ;set your functions here: (this is the part that recognize your remote ctrl keys) case 0 if $iMsg = 2560 Then GUICtrlSetData($display_label, "Power") EndIf case 1 ;dunno case 2 ;dunno case 3 GUICtrlSetData($display_label, "Full screen") case 4 GUICtrlSetData($display_label, "Vol +") case 5 GUICtrlSetData($display_label, "Ch. 1") case 6 GUICtrlSetData($display_label, "Ch. 2") case 7 GUICtrlSetData($display_label, "Ch. 3") case 8 GUICtrlSetData($display_label, "Vol -") case 9 GUICtrlSetData($display_label, "Ch. 4") case 10 GUICtrlSetData($display_label, "Ch. 5") Case 11 GUICtrlSetData($display_label, "Ch. 6") case 12 GUICtrlSetData($display_label, "Ch. UP") case 13 GUICtrlSetData($display_label, "Ch. 7") case 14 GUICtrlSetData($display_label, "Ch. 8") Case 15 GUICtrlSetData($display_label, "Ch. 9") case 16 GUICtrlSetData($display_label, "Ch. Down") case 17 GUICtrlSetData($display_label, "Switch to previous") case 18 GUICtrlSetData($display_label, "Ch. 0") case 19 GUICtrlSetData($display_label, "Enter") case 20 GUICtrlSetData($display_label, "Mute") case 22 GUICtrlSetData($display_label, "Display") case 27 GUICtrlSetData($display_label, "Audio") case 30 GUICtrlSetData($display_label, "Video") case 31 GUICtrlSetData($display_label, "Teletext") case 64 GUICtrlSetData($display_label, "Sleep") case 65 GUICtrlSetData($display_label, ". (Dot)") case 66 GUICtrlSetData($display_label, "Previous") case 67 GUICtrlSetData($display_label, "Play/Pause") case 68 GUICtrlSetData($display_label, "Next") case 69 GUICtrlSetData($display_label, "Time Shifting") case 70 GUICtrlSetData($display_label, "Stop") case 71 GUICtrlSetData($display_label, "Rec") case 72 GUICtrlSetData($display_label, "(M) SnapShot") case 73 GUICtrlSetData($display_label, "Boss Key") case 74 GUICtrlSetData($display_label, "Pic. in Pic.") case 75 GUICtrlSetData($display_label, "Red color") case 76 GUICtrlSetData($display_label, "Green color") case 77 GUICtrlSetData($display_label, "Yellow color") case 78 GUICtrlSetData($display_label, "Blue color") case 79 GUICtrlSetData($display_label, "Menu") case 80 GUICtrlSetData($display_label, "Cancel") case 81 GUICtrlSetData($display_label, "Chan. Surf") case 82 GUICtrlSetData($display_label, "[...]") case 83 GUICtrlSetData($display_label, "EPG") case 84 GUICtrlSetData($display_label, "Backward") case 85 GUICtrlSetData($display_label, "Forward") case 1011 ;DVD or sometimes FM, so disable and not use is the best solution case Else GUICtrlSetData($display_label, "key for case: " & @CRLF & $wParam & @CRLF & "is not defined...") EndSwitch Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;---------------------------------------------------------------------------------------- ; register class function and it's details/authors shown below ; link: http://www.autoitscript.com/forum/index.php?showtopic=79575 ;---------------------------------------------------------------------------------------- #cs _WinAPI_RegisterClassEx($sClassName, $sCallbackFunction, $hIcon=0, $hCursor=0, $iBkColor=$COLOR_BTNFACE, $iStyle=$CS_DEFAULTSTYLE) $sClassName - Classname $sCallbackFunction - WindowProc callback function $hIcon - Handle to a icon which will be be used as the window icon (Default = application icon) $hCursor - Handle to cursor which will be used as the window cursor (Default = arraow cursor) Use _WinAPI_LoadCursor() [also included with this UDF] to load a system cursor: $CURSOR_ARROW $CURSOR_IBEAM $CURSOR_WAIT $CURSOR_CROSS $CURSOR_UPARROW $CURSOR_SIZENWSE $CURSOR_SIZENESW $CURSOR_SIZEWE $CURSOR_SIZENS $CURSOR_SIZEALL $CURSOR_NO $CURSOR_APPSTARTING $CURSOR_HELP Example: _WinAPI_LoadCursor(0, $CURSOR_IBEAM) Do not use the $IDC_ constants declared in Constants.au3 $iBkColor - RGB color code of window background color $iStyle - Class style. A combination of these values: (Default = $CS_DEFAULTSTYLE) $CS_VREDRAW $CS_HREDRAW $CS_DBLCLKS $CS_OWNDC $CS_CLASSDC $CS_PARENTDC $CS_NOCLOSE $CS_SAVEBITS $CS_BYTEALIGNCLIENT $CS_BYTEALIGNWINDOW $CS_GLOBALCLASS $CS_DROPSHADOW Function: Creating a class which can be used with CreateWindowEx, and others Author: Original - amel27 Working version - Kip #ce Func _WinAPI_RegisterClassEx($sClassName, $sCallbackFunction="", $hIcon=0, $hCursor=0, $iBkColor=$COLOR_BTNFACE, $iStyle=$CS_DEFAULTSTYLE) If not $hIcon Then Local $aIcon = DllCall("user32.dll", "hwnd", "LoadIcon", "hwnd", 0, "int", $IDI_APPLICATION) $hIcon = $aIcon[0] EndIf If not $hCursor Then $hCursor = _WinAPI_LoadCursor(0,$CURSOR_ARROW) EndIf local $hWndProc = DLLCallbackRegister ($sCallbackFunction, "int", "hwnd;int;wparam;lparam") Local $pCallback = DllCallbackGetPtr($hWndProc) Local $tWndClassEx = DllStructCreate("uint cbSize;uint style;ptr lpfnWndProc;int cbClsExtra;int cbWndExtra;hwnd hInstance;hwnd hIcon;hwnd hCursor;hwnd hbrBackground;ptr lpszMenuName;ptr lpszClassName;hwnd hIconSm") Local $tClassName = DllStructCreate("char["& StringLen($sClassName)+1 &"]") DllStructSetData($tClassName, 1, $sClassName) DllStructSetData($tWndClassEx, "cbSize", DllStructGetSize($tWndClassEx) ) DllStructSetData($tWndClassEx, "style", $iStyle) DllStructSetData($tWndClassEx, "lpfnWndProc", $pCallback) DllStructSetData($tWndClassEx, "hInstance", _WinAPI_GetModuleHandle("")) DllStructSetData($tWndClassEx, "hIcon", $hIcon) DllStructSetData($tWndClassEx, "hCursor", $hCursor) DllStructSetData($tWndClassEx, "hbrBackground", _WinAPI_CreateSolidBrush(RGB_to_BGR($iBkColor))) DllStructSetData($tWndClassEx, "lpszClassName", DllStructGetPtr($tClassName)) DllStructSetData($tWndClassEx, "hIconSm", $hIcon) Local $aRet = DllCall("user32.dll", "dword", "RegisterClassExA", "ptr", DllStructGetPtr($tWndClassEx) ) Return $aRet[0] EndFunc Func _WinAPI_UnregisterClass($sClassName) Local $aRet = DllCall("user32.dll", "int", "UnregisterClassA", "str", $sClassName, "hwnd", _WinAPI_GetModuleHandle("")) Return $aRet[0] EndFunc Func _WinAPI_LoadCursor($hInstance, $iCursor) $GuiCursor = DllCall("user32.dll", "hwnd", "LoadCursor", "hwnd", $hInstance, "int", $iCursor) Return $GuiCursor[0] EndFunc Func RGB_to_BGR($BRG) $b = BitAND(BitShift($BRG, 16), 0xFF) $g = BitAND(BitShift($BRG, 8), 0xFF) $r = BitAND($BRG, 0xFF) Return "0x"&Hex($r,2)&Hex($g,2)&Hex($b,2) EndFunc
...would be great if some leadtek TV card owners could test ;]
Edited by sandin, 23 August 2009 - 11:33 AM.





