为了改变鼠标左键,需要调用API函数SwapMouseButton。这样可以不用通知控制面板而改变鼠标左键。我们需要修改注册表。以下代码表明,先读注册表,决定鼠标左键开关的当前值,并通过写注册表运行SwapMouseButton函数。
uses Windows, Registry ;
const
LeftButton = '0' ;
RightButton = '1' ;
VaueToRead = 'SwapMouseButtons' ;
begin
with TRegistry.Create do
begin
try
if OpenKey('Control Panel\Mouse',False) then
begin
if ValueExists(VaueToRead) then
if ReadString(VaueToRead) = LeftButton then
begin
SwapMouseButton(True) ;
WriteString(VaueToRead,RightButton) ;
end else
begin
SwapMouseButton(False) ;
WriteString(VaueToRead,LeftButton) ;
end ;
CloseKey ;
end ;
finally
Free ;
end ;
end ;
end.
uses Windows, Registry ;
const
LeftButton = '0' ;
RightButton = '1' ;
VaueToRead = 'SwapMouseButtons' ;
begin
with TRegistry.Create do
begin
try
if OpenKey('Control Panel\Mouse',False) then
begin
if ValueExists(VaueToRead) then
if ReadString(VaueToRead) = LeftButton then
begin
SwapMouseButton(True) ;
WriteString(VaueToRead,RightButton) ;
end else
begin
SwapMouseButton(False) ;
WriteString(VaueToRead,LeftButton) ;
end ;
CloseKey ;
end ;
finally
Free ;
end ;
end ;
end.