Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

KeyboardDevice.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * キーボードデバイス実装
00022  * @author Junpee
00023  */
00024 
00025 #include "LampBasic.h"
00026 #include "Input/Keyboard/KeyboardDevice.h"
00027 
00028 namespace Lamp{
00029 
00030 //------------------------------------------------------------------------------
00031 // コンストラクタ
00032 KeyboardDevice::KeyboardDevice() : InputDevice(false){
00033 }
00034 //------------------------------------------------------------------------------
00035 // デストラクタ
00036 KeyboardDevice::~KeyboardDevice(){
00037 }
00038 //------------------------------------------------------------------------------
00039 // 初期化
00040 bool KeyboardDevice::initialize(
00041     DirectInputDevice* inputDevice, HWND windowHandle){
00042     if(!InputDevice::initialize(inputDevice, windowHandle)){ return false; }
00043     // データフォーマットの指定
00044     if(DirectXFailed(inputDevice->SetDataFormat(&c_dfDIKeyboard))){
00045         ErrorOut("Keyboard::initialize() "
00046             "キーボードのデータフォーマット指定に失敗しました。");
00047         return false;
00048     } 
00049     // 優先度の指定
00050     if(!setCooperativeLevel(isExclusive(), isForeground())){ return false; }
00051     return true;
00052 }
00053 //------------------------------------------------------------------------------
00054 // ポーリング
00055 bool KeyboardDevice::polling(){
00056     InputDevice::polling();
00057     u_char state[maxKeyCount];
00058     HRESULT result = inputDevice_->GetDeviceState(
00059         sizeof(u_char) * maxKeyCount, &state);
00060     if(DirectXSucceeded(result)){
00061         for(int i = 0; i < maxKeyCount; i++){
00062             keyboardState_.setKeyPressed((Key)i, ((state[i] & 0x80) != 0));
00063         }
00064         return true;
00065     }else{
00066         // エラーなら入力無し
00067         keyboardState_.clear();
00068         // 深刻なエラーでないかチェック
00069         if((result != DIERR_INPUTLOST) && (result != DIERR_NOTACQUIRED)){
00070             ErrorOut("GetDeviceState()に失敗しました。");
00071         }else{
00072             // デバイス再取得
00073             acquire();
00074         }
00075     }
00076     return false;
00077 }
00078 //------------------------------------------------------------------------------
00079 } // End of namespace Lamp
00080 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:31 2005 for Lamp by doxygen 1.3.2