Solved

setting mouse essped delphi 7

Posted on 2010-08-25
21
925 Views
Last Modified: 2012-05-10
how to change the mouse speed into a delphi 7 application? I mean, I want to inform the new speed value on running application.
0
Comment
Question by:PsyProg
  • 10
  • 4
  • 4
  • +2
21 Comments
 
LVL 8

Expert Comment

by:BdLm
ID: 33525814
is this the solution you need ?


http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_11060127.html

if yes, we can port that code to delphi  

0
 

Author Comment

by:PsyProg
ID: 33526041
I tried this:

mspeed[0] := 0;
mspeed[1] := 0;      
mspeed[2] := 0;

and this

mspeed[0] := 4;
mspeed[1] := 6;      
mspeed[2] := 2;;

                                               
if not SystemParametersInfo(SPI_SETMOUSE, 0, @mspeed[0], 0) then
showmessage('Error');

No error message and NO mouse speed alteration...

any new idea? tks
0
 

Author Comment

by:PsyProg
ID: 33526056
I read thar "spi_setmousespeed" doesn't work at windows xp, but "spi_setmouse" works?
0
 
LVL 8

Expert Comment

by:BdLm
ID: 33526507


NOT
 
  SystemParametersInfo(SPI_SETMOUSE, 0, @speed, SPIF_SENDCHANGE);
 
 BUT
 
  SystemParametersInfo(SPI_SETMOUSE, 0, @a, SPIF_SENDCHANGE)
0
 

Author Comment

by:PsyProg
ID: 33526726
BdLm,

I appreciate your attention, but doesn't work yet. the name of the varaible after "@" doesn't matter, since you have wrote them like array[0..2] of integer.

i know that the statement "if not SystemParametersInfo(SPI_SETMOUSE, 0, @mspeed[0], 0) then
showmessage('Error');"  has been reading without error, but the question is why the mouse keeps the same speed? I tried "@mspeed" and "@mspeed[0]" (like the link you show me). and I tried with "@a"...

tks

0
 

Author Comment

by:PsyProg
ID: 33526737
and

I tried the fourth part with:
SPIF_SENDCHANGE - no error
SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE - error
SPIF_SENDWININICHANGE - error
SPIF_UPDATEINIFILE - error
0 - no error

but no mouse speed alteration.

[]
0
 
LVL 25

Expert Comment

by:epasquier
ID: 33527674
@mspeed and @mspeed[0] are completely equivalent.

I found some similar codes (even Delphi ones) and tested them too but to no effect.
On one topic, some people where saying that it worked for them, and other said that it had no effect, so I guess this method just don't work with some OS/mouse drivers combinations. That was the conclusion of those guys in the source website.

Another way of doing that will have to be found....
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 33528146
Remove the @... just pass by value, the doc is wrong

SystemParametersInfo(SPI_SETMOUSE, 0, 20, SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
0
 

Author Comment

by:PsyProg
ID: 33529897
hi epasquier and DragonSlayer,

tanks for the help.

the delphi code doesn't compile with a integer value at the third place. Message: incompatible types: Integer  and Pointer.

tks
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 33530178
Hi PsyProg...

1. Have you tried with SPI_SETMOUSESPEED instead?
2. There have been forums that shows people redefining their call to SystemsParameterInfo to send an actual value instead of a pointer
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 33530191
0
 
LVL 8

Expert Comment

by:BdLm
ID: 33530301
0
 

Author Comment

by:PsyProg
ID: 33530326
Can you help me to translate this VB code,

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Integer, ByVal fuWinIni As Long) As Long

to delphi code?

how should this part (Lib "user32" Alias "SystemParametersInfoA") be write into delphi code?

tks
0
 

Author Comment

by:PsyProg
ID: 33530359
Hi BdLm,

I read that post before, but this is the solution that doesn't generate error and still doesn't change the speed mouse...

I am inclinated to try the alternative to redelcare the function SystemParametersInfo into the code...but i don't know how to translate the Vb to delphi...

tks
0
 
LVL 8

Expert Comment

by:BdLm
ID: 33530415
not talking on the vb solution the link on the delpho pages, last post here was: solutions works fine

0
 

Author Comment

by:PsyProg
ID: 33530637
my code following the delphi page you posted::

procedure Mousesol;
var
a: array [0..2] of integer;
begin
a[0] := 0;   //4; // threshold value
a[1] := 0;   //6; // threshold value
a[2] := 0;   //2; // mouse speed        
if not SystemParametersInfo(SPI_SETMOUSE, 0, @a, SPIF_SENDCHANGE) then
showmessage('Tem Erro Aqui');
end;

I also tried without "if not then"...

I tried several changes on the parameters third and fourth...but nothing.

the fourth part with:
SPIF_SENDCHANGE - no error
SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE - no error
SPIF_SENDWININICHANGE - no error
SPIF_UPDATEINIFILE - no error
0 - no error

the third part with
0 0 0
6 4 2
0 0 5
20 20 20
1 1 1
3 3 3
so on...

that is the reason i want to try the vb solution redeclaring the function...

tks

0
 
LVL 14

Expert Comment

by:systan
ID: 33533193
PsyProg;
Here you go!
var

   reg:TRegistry;

begin

   reg:=TRegistry.Create;

   with reg do begin

    try

     if OpenKey('\Control Panel\mouse', False) then begin

      reg.WriteString ('MouseSensitivity','20') ;

      reg.WriteString ('MouseSpeed','1') ;

      SystemParametersInfo (SPI_SETMOUSE,0, nil,SPIF_SENDWININICHANGE) ;

     end

    finally

      reg.Free;

    end;

   end;

end;

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 33533342
Or using the ScrollBar;
Don't forget the : uses Registry;
procedure TForm1.FormCreate(Sender: TObject);

begin

Scrollbar1.max:=20;

Scrollbar1.OnChange := ScrollBar1Change;

end;



procedure TForm1.ScrollBar1Change(Sender: TObject);

var

   reg:TRegistry;

begin

   reg:=TRegistry.Create;

   with reg do begin

    try

     if OpenKey('\Control Panel\mouse', False) then begin

      reg.WriteString ('MouseSensitivity', inttostr(ScrollBar1.position)) ;

      SystemParametersInfo (SPI_SETMOUSE,0, nil,SPIF_SENDWININICHANGE) ;

     end

    finally

      reg.Free;

    end;

   end;

end;

Open in new window

0
 
LVL 14

Accepted Solution

by:
DragonSlayer earned 500 total points
ID: 33533737
Hi again,

So sorry for my earlier comments, I wrote 'em without actually trying out some code for myself.

Anyway, finally gotten about starting Delphi and coding, and found that this works:
var

  Speed: Integer;

begin

  Speed := 15;

  SystemParametersInfo(SPI_SETMOUSESPEED, 1, Pointer(Speed), SPIF_SENDCHANGE or SPIF_UPDATEINIFILE);

end;

Open in new window

0
 

Author Closing Comment

by:PsyProg
ID: 33533857
perfect.
0
 

Author Comment

by:PsyProg
ID: 33533870
systan,

I still need to try your code, but the DragonSlayer's code works just fine.

tks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 63
mapAB Challlenge 35 123
LAN or WAN ? 11 81
Unique identifier on a terminal server (rdp) 4 45
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now