📄 hid.pas
字号:
unit Hid;
{$WEAKPACKAGEUNIT}
interface
(*$HPPEMIT ''*)
(*$HPPEMIT '#include "hidusage.h"'*)
(*$HPPEMIT '#include "hidpi.h"'*)
(*$HPPEMIT ''*)
uses
Windows;
type
// (rom) moved from HidUsage.pas
PUsage = ^TUsage;
TUsage = Word;
// (rom) from WINNT.H
NTSTATUS = LongInt;
{$EXTERNALSYM NTSTATUS}
// FACILITY_HID_ERROR_CODE defined in ntstatus.h
const
FACILITY_HID_ERROR_CODE = $11;
{$EXTERNALSYM FACILITY_HID_ERROR_CODE}
//
// Define NT Status codes with Facility Code of FACILITY_HID_ERROR_CODE
// (rom) vv
HIDP_STATUS_SUCCESS = NTSTATUS($00110000);
{$EXTERNALSYM HIDP_STATUS_SUCCESS}
HIDP_STATUS_NULL = NTSTATUS($80110001);
{$EXTERNALSYM HIDP_STATUS_NULL}
HIDP_STATUS_INVALID_PREPARSED_DATA = NTSTATUS($C0110001);
{$EXTERNALSYM HIDP_STATUS_INVALID_PREPARSED_DATA}
HIDP_STATUS_INVALID_REPORT_TYPE = NTSTATUS($C0110002);
{$EXTERNALSYM HIDP_STATUS_INVALID_REPORT_TYPE}
HIDP_STATUS_INVALID_REPORT_LENGTH = NTSTATUS($C0110003);
{$EXTERNALSYM HIDP_STATUS_INVALID_REPORT_LENGTH}
HIDP_STATUS_USAGE_NOT_FOUND = NTSTATUS($C0110004);
{$EXTERNALSYM HIDP_STATUS_USAGE_NOT_FOUND}
HIDP_STATUS_VALUE_OUT_OF_RANGE = NTSTATUS($C0110005);
{$EXTERNALSYM HIDP_STATUS_VALUE_OUT_OF_RANGE}
HIDP_STATUS_BAD_LOG_PHY_VALUES = NTSTATUS($C0110006);
{$EXTERNALSYM HIDP_STATUS_BAD_LOG_PHY_VALUES}
HIDP_STATUS_BUFFER_TOO_SMALL = NTSTATUS($C0110007);
{$EXTERNALSYM HIDP_STATUS_BUFFER_TOO_SMALL}
HIDP_STATUS_INTERNAL_ERROR = NTSTATUS($C0110008);
{$EXTERNALSYM HIDP_STATUS_INTERNAL_ERROR}
HIDP_STATUS_I8042_TRANS_UNKNOWN = NTSTATUS($C0110009);
{$EXTERNALSYM HIDP_STATUS_I8042_TRANS_UNKNOWN}
HIDP_STATUS_INCOMPATIBLE_REPORT_ID = NTSTATUS($C011000A);
{$EXTERNALSYM HIDP_STATUS_INCOMPATIBLE_REPORT_ID}
HIDP_STATUS_NOT_VALUE_ARRAY = NTSTATUS($C011000B);
{$EXTERNALSYM HIDP_STATUS_NOT_VALUE_ARRAY}
HIDP_STATUS_IS_VALUE_ARRAY = NTSTATUS($C011000C);
{$EXTERNALSYM HIDP_STATUS_IS_VALUE_ARRAY}
HIDP_STATUS_DATA_INDEX_NOT_FOUND = NTSTATUS($C011000D);
{$EXTERNALSYM HIDP_STATUS_DATA_INDEX_NOT_FOUND}
HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = NTSTATUS($C011000E);
{$EXTERNALSYM HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE}
HIDP_STATUS_BUTTON_NOT_PRESSED = NTSTATUS($C011000F);
{$EXTERNALSYM HIDP_STATUS_BUTTON_NOT_PRESSED}
HIDP_STATUS_REPORT_DOES_NOT_EXIST = NTSTATUS($C0110010);
{$EXTERNALSYM HIDP_STATUS_REPORT_DOES_NOT_EXIST}
HIDP_STATUS_NOT_IMPLEMENTED = NTSTATUS($C0110020);
{$EXTERNALSYM HIDP_STATUS_NOT_IMPLEMENTED}
//
// We blundered this status code.
//
HIDP_STATUS_I8242_TRANS_UNKNOWN = HIDP_STATUS_I8042_TRANS_UNKNOWN;
{$EXTERNALSYM HIDP_STATUS_I8242_TRANS_UNKNOWN}
// Special Link collection values for using the query functions
//
// Root collection references the collection at the base of the link
// collection tree.
// Unspecifies, references all collections in the link collection tree.
HIDP_LINK_COLLECTION_ROOT = -1;
{$EXTERNALSYM HIDP_LINK_COLLECTION_ROOT}
HIDP_LINK_COLLECTION_UNSPECIFIED = 0;
{$EXTERNALSYM HIDP_LINK_COLLECTION_UNSPECIFIED}
// A bitmap of the current shift state of the keyboard when using the
// below keyboard usages to i8042 translation function.
const
// (rom) values for the bits of THIDPKeyboardModifierState
kmsLeftControl = $0001;
kmsLeftShift = $0002;
kmsLeftAlt = $0004;
kmsLeftGUI = $0008;
kmsRightControl = $0010;
kmsRightShift = $0020;
kmsRightAlt = $0040;
kmsRightGUI = $0080;
kmsCapsLock = $0100;
kmsScollLock = $0200;
kmsNumLock = $0400;
type
THIDPKeyboardModifierState = DWORD;
{$EXTERNALSYM THIDPKeyboardModifierState}
// (rom) bit value to check IsAlias of THIDPLinkCollectionNode
const
lcnIsAlias = 1;
type
// (rom) to represent the union names
THIDVariantFlags = (Range, NotRange);
PHIDDConfiguration = ^THIDDConfiguration;
_HIDD_CONFIGURATION = packed record
cookie: Pointer;
size: ULONG;
RingBufferSize: ULONG;
end;
{$EXTERNALSYM _HIDD_CONFIGURATION}
THIDDConfiguration = _HIDD_CONFIGURATION;
PHIDDAttributes = ^THIDDAttributes;
_HIDD_ATTRIBUTES = packed record
Size: ULONG; // size of structure (set before call)
VendorID: Word;
ProductID: Word;
VersionNumber: Word;
//
// Additional fields will be added to the end of this structure.
//
end;
{$EXTERNALSYM _HIDD_ATTRIBUTES}
THIDDAttributes = _HIDD_ATTRIBUTES;
// (rom) should be Pointer but Delphi 4 objects if used as published property
PHIDPPreparsedData = DWORD;
{$EXTERNALSYM PHIDPPreparsedData}
const
HidP_Input = 0;
{$EXTERNALSYM HidP_Input}
HidP_Output = 1;
{$EXTERNALSYM HidP_Output}
HidP_Feature = 2;
{$EXTERNALSYM HidP_Feature}
type
PHIDPReportType = ^THIDPReportType;
THIDPReportType = DWORD;
const
// Produce Make or Break Codes
HidP_Keyboard_Break = 0;
{$EXTERNALSYM HidP_Keyboard_Break}
HidP_Keyboard_Make = 1;
{$EXTERNALSYM HidP_Keyboard_Make}
type
PHIDPKeyboardDirection = ^THIDPKeyboardDirection;
THIDPKeyboardDirection = DWORD;
PUsageAndPage = ^TUsageAndPage;
_USAGE_AND_PAGE = packed record
Usage: TUsage;
UsagePage: TUsage;
end;
{$EXTERNALSYM _USAGE_AND_PAGE}
TUsageAndPage = _USAGE_AND_PAGE;
PHIDPButtonCaps = ^THIDPButtonCaps;
_HIDP_BUTTON_CAPS = packed record
UsagePage: TUsage;
ReportID: BYTE;
IsAlias: ByteBool;
BitField: Word;
LinkCollection: Word; // A unique internal index pointer
LinkUsage: TUsage;
LinkUsagePage: TUsage;
IsRange: ByteBool;
IsStringRange: ByteBool;
IsDesignatorRange: ByteBool;
IsAbsolute: ByteBool;
Reserved: array [0..9] of ULONG;
case THIDVariantFlags of
Range:
( UsageMin, UsageMax: TUsage;
StringMin, StringMax,
DesignatorMin, DesignatorMax,
DataIndexMin, DataIndexMax: Word );
NotRange:
( Usage, Reserved1: TUsage;
StringIndex, Reserved2,
DesignatorIndex, Reserved3,
DataIndex, Reserved4: Word );
end;
{$EXTERNALSYM _HIDP_BUTTON_CAPS}
THIDPButtonCaps = _HIDP_BUTTON_CAPS;
PHIDPValueCaps = ^THIDPValueCaps;
_HIDP_VALUE_CAPS = packed record
UsagePage: TUsage;
ReportID: BYTE;
IsAlias: ByteBool;
BitField: Word;
LinkCollection: Word; // A unique internal index pointer
LinkUsage: TUsage;
LinkUsagePage: TUsage;
IsRange: ByteBool;
IsStringRange: ByteBool;
IsDesignatorRange: ByteBool;
IsAbsolute: ByteBool;
HasNull: ByteBool; // Does this channel have a null report union
Reserved: BYTE;
BitSize: Word; // How many bits are devoted to this value?
ReportCount: Word; // See Note below. Usually set to 1.
Reserved_: array [0..4] of Word;
// (rom) name change Reserved2 gives name clash in Pascal
UnitsExp: ULONG;
Units: ULONG;
LogicalMin: Integer;
LogicalMax: Integer;
PhysicalMin: Integer;
PhysicalMax: Integer;
case THIDVariantFlags of
Range:
( UsageMin, UsageMax: TUsage;
StringMin, StringMax,
DesignatorMin, DesignatorMax,
DataIndexMin, DataIndexMax: Word );
NotRange:
( Usage, Reserved1: TUsage;
StringIndex, Reserved2,
DesignatorIndex, Reserved3,
DataIndex, Reserved4: Word );
end;
{$EXTERNALSYM _HIDP_VALUE_CAPS}
THIDPValueCaps = _HIDP_VALUE_CAPS;
//
// Notes:
//
// ReportCount: When a report descriptor declares an Input, Output, or
// Feature main item with fewer usage declarations than the report count, then
// the last usage applies to all remaining unspecified count in that main item.
// (As an example you might have data that required many fields to describe,
// possibly buffered bytes.) In this case, only one value cap structure is
// allocated for these associtated fields, all with the same usage, and Report
// Count reflects the number of fields involved. Normally ReportCount is 1.
// To access all of the fields in such a value structure would require using
// HidP_GetUsageValueArray and HidP_SetUsageValueArray. HidP_GetUsageValue/
// HidP_SetScaledUsageValue will also work, however, these functions will only
// work with the first field of the structure.
//
//
// The link collection tree consists of an array of LINK_COLLECTION_NODES
// where the index into this array is the same as the collection number.
//
// Given a collection A which contains a subcollection B, A is defined to be
// the parent B, and B is defined to be the child.
//
// Given collections A, B, and C where B and C are children of A, and B was
// encountered before C in the report descriptor, B is defined as a sibling of
// C. (This implies, of course, that if B is a sibling of C, then C is NOT a
// sibling of B).
//
// B is defined as the NextSibling of C if and only if there exists NO
// child collection of A, call it D, such that B is a sibling of D and D
// is a sibling of C.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -