tkeyboarddirect.cpp.svn-base

来自「ffshow源码」· SVN-BASE 代码 · 共 1,032 行 · 第 1/3 页

SVN-BASE
1,032
字号
/* * Copyright (c) 2002-2006 Milan Cutka * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */#include "stdafx.h"#include "TkeyboardDirect.h"#include "IffdshowBase.h"#include "IffdshowDec.h"#include "IffdshowDecVideo.h"#include "ffdshow_constants.h"#include "reg.h"#include "ffdebug.h"#include "Tconfig.h"//============================ TdirectInput ============================TdirectInput::TdirectInput(TintStrColl *Icoll,const char_t *Iname,const GUID &IdeviceId,const DIDATAFORMAT &IdeviceFormat,void *Istate,void *Istateprev,size_t Istatesize,IffdshowBase *Ideci): Toptions(Icoll), name(Iname), state(Istate), stateprev(Istateprev), statesize(Istatesize), deci(Ideci), deviceId(IdeviceId),deviceFormat(IdeviceFormat){ tsprintf(classname,_l("ffdshow_%s_%i"),name,rand()%1000); di=NULL;did=NULL;event=NULL;h=NULL;thr=0; inExplorer=deci->inExplorer()==S_OK;}void TdirectInput::onChange(int id,int newval){ if (is && !inExplorer)  {   int mode=deci->getParam2(IDFF_filterMode);   if ((mode&IDFF_FILTERMODE_PLAYER) && !(mode&IDFF_FILTERMODE_VFW))    {     if (!di)      hook();    }     else     {     if (di)      unhook();    }    }  }void TdirectInput::load(void){ TregOpRegRead t(HKEY_CURRENT_USER,FFDSHOW_REG_PARENT _l("\\") FFDSHOWDECVIDEO); reg_op(t);}void TdirectInput::save(void){ TregOpRegWrite t(HKEY_CURRENT_USER,FFDSHOW_REG_PARENT _l("\\") FFDSHOWDECVIDEO); reg_op(t);}void TdirectInput::hook(void){ if (di) unhook(); DPRINTF(_l("hook")); DirectInputCreate(0,DIRECTINPUT_VERSION,&di,NULL);if (!di) return; di->CreateDevice(deviceId,&did,NULL);if (!did) return; h=createInvisibleWindow(0,classname,classname,DefWindowProc,0,NULL); if (!h) return; if (did->SetCooperativeLevel(h,DISCL_BACKGROUND|DISCL_NONEXCLUSIVE)!=S_OK) return; if (did->SetDataFormat(&deviceFormat)!=S_OK) return; char_t eventname[50];tsprintf(eventname,_l("ffdshow %s event"),name); event=CreateEvent(NULL,FALSE,FALSE,eventname);if (!event) return; if (did->SetEventNotification(event)!=S_OK) return; if (did->Acquire()!=S_OK) return; terminate=false; thr=_beginthread(thread,16384,this);}void TdirectInput::unhook(void){ if (!di) return; DPRINTF(_l("unhook")); if (thr)   {   terminate=true;   while (terminate);  } if (did)  {   did->Unacquire();   did->SetEventNotification(NULL);   if (event) CloseHandle(event);event=NULL;   did->Release();   did=NULL;  } if (di) di->Release();di=NULL; if (h) DestroyWindow(h); HINSTANCE hi;deci->getInstance(&hi); UnregisterClass(classname,hi);}void TdirectInput::thread(void *self0){ TdirectInput *self=(TdirectInput*)self0; setThreadName(DWORD(-1),text<char>(self->name)); self->did->GetDeviceState((DWORD)self->statesize,self->stateprev); while (!self->terminate)  {   HRESULT res=WaitForSingleObject(self->event,100);   if (res==WAIT_OBJECT_0 || res==WAIT_TIMEOUT)    {     self->did->GetDeviceState((DWORD)self->statesize,self->state);     self->processState();     memcpy(self->stateprev,self->state,self->statesize);    }  } self->terminate=false;} bool TdirectInput::windowActive(void){ HWND tw=GetForegroundWindow(); DWORD tpid=0;GetWindowThreadProcessId(tw,&tpid); DWORD cpid=GetCurrentProcessId(); return cpid==tpid;}//============================== Tkeyboard =============================void Tkeyboard::reg_op(TregOp &t){ TdirectInput::reg_op(t); char_t pomS[256]; for (TkeysParams::iterator i=keysParams.begin();i!=keysParams.end();i++)  t._REG_OP_N(0,strcpyf(pomS,_l("key %s"),i->descr),i->key,i->key);}void Tkeyboard::initKeysParam(void){ keysParams.push_back(TkeyParam(_l("Activation key 1"),VK_CONTROL));i_key_act1=0; keysParams.push_back(TkeyParam(_l("Activation key 2"),VK_MENU));i_key_act2=1; keysParams.push_back(TkeyParam(_l("Second function") ,VK_SHIFT));i_key_mod=2; keysParams.push_back(TkeyParam(_l("Seek forward") ,VK_RIGHT,idff_forward )); keysParams.push_back(TkeyParam(_l("Seek backward"),VK_LEFT ,idff_backward));  keysParams.push_back(TkeyParam(_l("Toggle OSD"),'O',IDFF_isOSD)); keysParams.push_back(TkeyParam(_l("Toggle visualizations"),'V',IDFF_isVis)); keysParams.push_back(TkeyParam(_l("Toggle crop/zoom"),'C',IDFF_isCropNzoom)); keysParams.push_back(TkeyParam(_l("Toggle deinterlace"),'D',IDFF_isDeinterlace)); keysParams.push_back(TkeyParam(_l("Toggle levels"),'L',IDFF_isLevels)); keysParams.push_back(TkeyParam(_l("Toggle noise"),'N',IDFF_isNoise)); keysParams.push_back(TkeyParam(_l("Toggle picture properties"),'I',IDFF_isPictProp)); keysParams.push_back(TkeyParam(_l("Toggle postprocessing"),'P',IDFF_isPostproc)); keysParams.push_back(TkeyParam(_l("Toggle blur"),'B',IDFF_isBlur)); keysParams.push_back(TkeyParam(_l("Toggle resize"),'R',IDFF_isResize)); keysParams.push_back(TkeyParam(_l("Toggle subtitles"),'S',IDFF_isSubtitles)); keysParams.push_back(TkeyParam(_l("Toggle sharpen"),'H',IDFF_isSharpen)); keysParams.push_back(TkeyParam(_l("Toggle flip"),'F',IDFF_flip)); keysParams.push_back(TkeyParam(_l("Toggle avisynth"),'A',IDFF_isAvisynth)); keysParams.push_back(TkeyParam(_l("Toggle warpsharp"),'W',IDFF_isWarpsharp)); keysParams.push_back(TkeyParam(_l("Grab frame"),'G',idff_grab));  keysParams.push_back(TkeyParam(_l("Subtitles delay/size decrease"),0x6d,idff_subdelaySub)); keysParams.push_back(TkeyParam(_l("Subtitles delay/size increase"),0x6b,idff_subdelayAdd)); keysParams.push_back(TkeyParam(_l("Subtitles position decrease"),0x21,idff_subposSub)); keysParams.push_back(TkeyParam(_l("Subtitles position increase"),0x22,idff_subposAdd)); keysParams.push_back(TkeyParam(_l("Decrease video delay"),0xbc,idff_videodelaySub)); keysParams.push_back(TkeyParam(_l("Increase video delay"),0xbe,idff_videodelayAdd)); keysParams.push_back(TkeyParam(_l("Previous preset"),0xdb,idff_presetPrev)); keysParams.push_back(TkeyParam(_l("Next preset"),0xdd,idff_presetNext));}void Tkeyboard::keyProc(int code,bool remote){ dkeys[DIK_LCONTROL]|=dkeys[DIK_RCONTROL]; dkeys[DIK_LALT]|=dkeys[DIK_RALT]; dkeys[DIK_LSHIFT]|=dkeys[DIK_RSHIFT]; dkeys[DIK_LMENU]|=dkeys[DIK_RMENU]; if (code==DIK_RCONTROL) code=DIK_LCONTROL; else if (code==DIK_RALT) code=DIK_LALT; else if (code==DIK_RSHIFT) code=DIK_LSHIFT; else if (code==DIK_RMENU) code=DIK_LMENU; DPRINTF(_l("keyProc:%x"),code); if ((keysParams[i_key_act1].key && !dkeys[vk2dik[keysParams[i_key_act1].key]]) ||      (keysParams[i_key_act2].key && !dkeys[vk2dik[keysParams[i_key_act2].key]])) return; if (!always && !remote && !windowActive())  return; clock_t t1=clock(); bool isPress=t1-prevT>CLOCKS_PER_SEC/5; DPRINTF(_l("prev:%i, now:%i, isPress:%i"),prevT,t1,isPress); clock_t prevT0=prevT; prevT=t1; if (isPress)  {   comptrQ<IffdshowDec> deciD(deci);comptrQ<IffdshowDecVideo> deciV(deci);   bool isMod=keysParams[i_key_mod].key && dkeys[vk2dik[keysParams[i_key_mod].key]];   for (TkeysParams::const_iterator i=keysParams.begin();i!=keysParams.end();i++)    if (code==vk2dik[i->key])     if (i->idff>0 && !deci->getCfgDlgHwnd())      {       switch (i->idff)        {         case IDFF_isOSD:          if (isMod)           {            if (deci->getParam2(IDFF_isOSD))             deciV->cycleOSDpresets();            return;           }          break;          case IDFF_isSubtitles:          if (isMod)           {            if (deciV->cycleSubLanguages(+1)==S_OK && shortosd)              {              const char_t *lang;              deciV->getSubtitleLanguageDesc(deci->getParam2(IDFF_subCurLang),&lang);              if (lang && lang[0])               {                char_t msg[256];                tsprintf(msg,_l("subtitles language: %s"),lang);                deciV->shortOSDmessage(msg,30);               }              }             return;           }          break;        }           deci->invParam(i->idff);       deci->saveGlobalSettings();       deciD->saveActivePreset(NULL);       if (shortosd)        {         char_t msg[200];tsprintf(msg,_l("%s %s"),i->descr,deci->getParam2(i->idff)?_l("on"):_l("off"));         deciV->shortOSDmessage(msg,30);        }       return;      }      else       switch (i->idff)       {        case idff_forward:        case idff_backward:         {          if (deci->getState2()==State_Paused)           deciV->frameStep((i->idff==idff_backward?-1:1)*(isMod?10:1));          else           {            int pos;deciD->tell(&pos);            if (pos!=-1)             {              int sec=isMod?seek2:seek1;if (i->idff==idff_backward) sec*=-1;              if (SUCCEEDED(deciD->seek(pos+sec)) && shortosd)               {                char_t msg[100];                tsprintf(msg,_l("fast %s %i seconds"),sec<0?_l("backward"):_l("forward"),abs(sec));                deciV->shortOSDmessage(msg,30);               }             }           }          return;         }        case idff_grab:         deciV->grabNow();         return;         case idff_subdelaySub:         {          int idff=isMod?(deci->getParam2(IDFF_fontAutosize)?IDFF_fontSizeA:IDFF_fontSizeP):IDFF_subDelay;          deci->putParam(idff,deci->getParam2(idff)-(isMod?2:100));          if (shortosd)            {            char_t msg[256];            tsprintf(msg,_l("subtitles %s: %i"),isMod?_l("size"):_l("delay"),deci->getParam2(idff));            deciV->shortOSDmessage(msg,30);           }           return;         }         case idff_subdelayAdd:         {          int idff=isMod?(deci->getParam2(IDFF_fontAutosize)?IDFF_fontSizeA:IDFF_fontSizeP):IDFF_subDelay;          deci->putParam(idff,deci->getParam2(idff)+(isMod?2:100));          if (shortosd)            {            char_t msg[256];            tsprintf(msg,_l("subtitles %s: %i"),isMod?_l("size"):_l("delay"),deci->getParam2(idff));            deciV->shortOSDmessage(msg,30);           }           return;          }         case idff_subposSub:         {          int idff=isMod?IDFF_subPosX:IDFF_subPosY;          deci->putParam(idff,deci->getParam2(idff)-5);          if (shortosd)           {            char_t msg[256];            tsprintf(msg,_l("subtitles %s position : %i"),isMod?_l("horizontal"):_l("vertical"),deci->getParam2(idff));            deciV->shortOSDmessage(msg,30);           }          return;          }         case idff_subposAdd:         {          int idff=isMod?IDFF_subPosX:IDFF_subPosY;          deci->putParam(idff,deci->getParam2(idff)+5);          if (shortosd)           {            char_t msg[256];            tsprintf(msg,_l("subtitles %s position : %i"),isMod?_l("horizontal"):_l("vertical"),deci->getParam2(idff));            deciV->shortOSDmessage(msg,30);           }          return;          }         case idff_videodelayAdd:        case idff_videodelaySub:         {          //deci->putParam(IDFF_isVideoDelayEnd,0);          int delay=deci->getParam2(IDFF_videoDelay)+(i->idff==idff_videodelayAdd?20:-20);          deci->putParam(IDFF_videoDelay,delay);          if (shortosd)           {            char_t msg[256];            tsprintf(msg,_l("video delay: %i ms"),delay);            deciV->shortOSDmessage(msg,30);           }          return;         }        case idff_presetPrev:        case idff_presetNext:         {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?