direct input 标准调用

                                           读书笔记(direct input 部分)

    1.取得IDirectInput接口,DirectInput8Create

    2.获得接口后创建设备(鼠标,键盘...)

    3.设置设备协作等级,SetCooperativeLevel

    4.设置数据格式,SetDataFormat

    5.获取设备,Acquire

    6.使用设备,取得状态信息

    7.释放设备

例子如下:

if (DirectInput8Create(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput8, (void **)&lpdi,NULL)!=DI_OK)
   return(0);

// create a keyboard device  //////////////////////////////////
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
   return(0);


// set cooperation level
if (lpdikey->SetCooperativeLevel(main_window_handle,
                 DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
    return(0);

// set data format
if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
   return(0);

// acquire the keyboard
if (lpdikey->Acquire()!=DI_OK)
   return(0);

lpdikey->GetDeviceState(256, (LPVOID)keyboard_state);

// release keyboard
lpdikey->Unacquire();
lpdikey->Release();
lpdi->Release();

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页