Pensioner 0 Posted October 5 Hi. New here so apologies if this is posted in the wrong place. I've been searching for over a week now for an answer to this problem but have yet to find one that works. I have a need to change the mouse settings quickly depending on which PC/Laptop I'm working on because I find it difficult to see a white small cursor on screens. I want to be able to change it to BLACK and a size of 2. The size I am able to change but the colour I can't. I'm running XE8 and compiling on 32bit platform. The code I'm trying is as follows... Try MyReg := TRegistry.Create; MyReg.RootKey := HKEY_CURRENT_USER; if not (MyReg.OpenKey('\Control Panel\Cursors',False)) then begin MyReg.OpenKey('\Control Panel\Cursors',True); // tried this and it fails MyReg.WriteString('(default)','Windows Black'); // Also tried this which also fails MyReg.WriteString('','Windows Black'); MyReg.WriteInteger('CursorBaseSize',48); end; Finally FreeAndNil(MyReg); End; I'm hoping my quest ends here... Thank you all in advance... Share this post Link to post
Kas Ob. 124 Posted October 5 Try this procedure TForm10.Button1Click(Sender: TObject); var MyReg: TRegistry; begin MyReg := TRegistry.Create; try MyReg.RootKey := HKEY_CURRENT_USER; if MyReg.KeyExists('\Control Panel\Cursors') then begin MyReg.Access := KEY_WRITE or KEY_READ or KEY_WOW64_64KEY; // KEY_WRITE or KEY_READ together or we can separate them per operation if MyReg.OpenKey('\Control Panel\Cursors', False) then begin //st := MyReg.ReadString(''); MyReg.WriteString('', 'Windows Black'); end; end; finally MyReg.Free; end; end; Share this post Link to post
Pensioner 0 Posted October 5 Hi Kas. Many thanks for the response and code. Unfortunately it hasn't worked. Can't understand why this particular key is so hard to change. Share this post Link to post
Pensioner 0 Posted October 5 Someone slap me senseless.....!!!!.... I finally found the problem. I should have done this earlier. I stepped through the code and found I was missing a very important line. Why Delphi didn't report it as an error I don't know. The line I was so stupidly missing was in Kas's code but I stupidly only copied his code between the Try and finally section. What a plonker!!! Maybe I'm getting too old for this now...lol Kas many thanks for your help... MyReg := TRegistry.Create; Share this post Link to post
Pensioner 0 Posted October 7 Back again. As I stated previously i eventually, with help Kas, got this working. Having tried it now on at least 5 different laptops it does not work. It does modify the registry so the code works however it does not change the colour of the mouse cursor. Even after a reboot it still does not change. If I go into mouse settings it does indeed confirm that the changes where made. So I changed it back to white in Mouse Settings and then back to black again and the change is instant. So what else needs to be done in delphi code to actually apply the settings made? Share this post Link to post
Anders Melander 1815 Posted October 7 On my system (Windows 10) the mouse pointer color setup is stored in HKCU\SOFTWARE\Microsoft\Accessibility\ in the values CursorColor and CursorType. However... I don't think this cursor color thing works the way you expect. AFAIK the values in the registry are only there so the Mouse Pointer control panel applet can display the current settings. The values indicate how the mouse pointer looks - they do not actually control it. What I think happens, when you change the mouse pointer color in the control panel, is that the applet create a set of cursor files with the desired color/mask and then write the config to the registry so it can display the setting the next time it is run. In other words, in order to change pointer colors, your application will need to: Create some cursor (.cur) files. Write them to the appropriate location on disk. Somehow get windows to load them. Share this post Link to post