掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
キーボードイベントのリアルタイム性を上げるには? (ID:36491)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
少し時間割いてみました。 キーを押しっぱなしにした時に送られてくるキーコードの時間間隔を測定しました。 私の所有しているキーボードはLogicool Classic Keyboard 200(1400円) http://www.logitech.com/index.cfm/keyboards/keyboard/devices/188&cl=jp,ja?section=overview CPUはCore2 Quad Q9550 2.83GHz Delphi2009 結果、99回のKeyDownで キー 間隔平均は0.033037秒、 標準偏差は0.000063秒でした。 最大誤差は0.0003秒(2%) CPUクロック数から時間への変換はExcel使ってます。^^; 比較的綺麗な図が描けました。 ざっとしか検証してませんが、重い動作をさせなければ一発目のキーも恐らく0.0003秒程度の精度は出ていると思います。 ちなみにこれを測定した時も、Excel,Outlook,WinAmp,IE,notepad,Delphiが起動してましたし、デバッグモードです。 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormCreate(Sender: TObject); private { Private 宣言 } Count : Integer; ClockData : array[0..100] of UInt64; public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.dfm} function GetCPUClock():UInt64; var Lo, Hi: DWORD; begin asm PUSH edx PUSH eax rdtsc MOV Lo, eax MOV Hi, edx POP eax POP edx end; Result := Hi; Result := (Result shl 32) or Lo; end; procedure TForm1.FormCreate(Sender: TObject); begin Count := 0; end; procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Count > 100 then begin beep; Exit; end; ClockData[Count] := GetCPUClock(); inc(Count); end; procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var i:Integer; strList : TStringList; begin strList := TStringList.Create; for i := 1 to 100-1 do begin strList.Add(IntToStr(ClockData[i+1]-ClockData[i])); end; strList.SaveToFile('data.txt'); ShowMessage(strList.Text); strList.Free; Count := 0; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.