How to make a custom mouse cursor in batch?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
back_slash
Posts: 19
Joined: 20 Aug 2021 08:07

How to make a custom mouse cursor in batch?

#1 Post by back_slash » 20 Aug 2021 08:12

Code: Select all

@echo off
chcp 65001 >nul
:start
timeout 0 >nul
cls
for /f "tokens=1,2 delims=:" %%A in ('Kernel\batbox /y') do (
 set y=%%B
 set x=%%A
)

Kernel\batbox /g %x% %y%
echo █
goto start
I am using this code, it does work, However, it has a delay and i'm not sure how to fix it for the intended effect
How do I fix it?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to make a custom mouse cursor in batch?

#2 Post by ShadowThief » 20 Aug 2021 10:13

Have you tried removing the timeout command?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to make a custom mouse cursor in batch?

#3 Post by aGerman » 20 Aug 2021 10:58

//EDIT: Scroll down to #14 for a tool which changes the mouse pointer.
Animation.gif
Animation.gif (73.48 KiB) Viewed 11513 times

back_slash
Posts: 19
Joined: 20 Aug 2021 08:07

Re: How to make a custom mouse cursor in batch?

#4 Post by back_slash » 20 Aug 2021 12:02

ShadowThief wrote:
20 Aug 2021 10:13
Have you tried removing the timeout command?
Yes, but that just makes it unreadable (it just clears the cmd screen at every moment)

back_slash
Posts: 19
Joined: 20 Aug 2021 08:07

Re: How to make a custom mouse cursor in batch?

#5 Post by back_slash » 20 Aug 2021 18:45

Also I mean like the MS-DOS 7.1 setup mouse cursor or the DOS 7.1 mouse cursor in general @aGerman

back_slash
Posts: 19
Joined: 20 Aug 2021 08:07

Re: How to make a custom mouse cursor in batch?

#6 Post by back_slash » 21 Aug 2021 06:16

Let me rephrase this:
How do I get ctmouse from dos in a batch file?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to make a custom mouse cursor in batch?

#7 Post by aGerman » 21 Aug 2021 07:20

Obviously Windows is not DOS, and there is no ctmouse. Besides of the fact that I don't even know what ctmouse is good for, what specific functionality of ctmouse are you after?
If it is about the shape, you can change the size of the horizontal bar using the .NET classes in a PowerShell invocation as shown above. (The Win32 API has a similar possibility but is also only accessible from within PowerShell). A different approch is using VT escape sequences where you can turn the cursor into a full block, an underscore, or a vertical bar. However, those escape sequences are only supported on Win10 (in the v2 console window).

Steffen

back_slash
Posts: 19
Joined: 20 Aug 2021 08:07

Re: How to make a custom mouse cursor in batch?

#8 Post by back_slash » 21 Aug 2021 11:44

@aGerman


I mean a mouse cursor as shown in this clip:
https://streamable.com/mqhntk
Do you know how I can get this? :?:
If so, it would be very much appreciated! :D

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to make a custom mouse cursor in batch?

#9 Post by aGerman » 21 Aug 2021 12:40

Oh, the mouse pointer is not related to the console window. Applications that run a window can change it if the window is entered. However, a Batch script runs in a cmd.exe process and the actual owner of the window is conhost.exe. One might be able to develop an external executable which hooks the mouse globally, hides the actual mouse pointer if it enters the window, and inverts the colors of the character cell if the pointer hovers over it. You need to have some experiences across Win32 API to accomplish this.

Steffen

back_slash
Posts: 19
Joined: 20 Aug 2021 08:07

Re: How to make a custom mouse cursor in batch?

#10 Post by back_slash » 21 Aug 2021 13:15

Well, I'm dumb as a rock when it comes to Win32 API and programming
Are there any currently published external commands to accomplish this?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to make a custom mouse cursor in batch?

#11 Post by ShadowThief » 21 Aug 2021 15:01

No, there is no demand at all for something like this. Batch scripts are meant to be interacted with entirely via the keyboard.

back_slash
Posts: 19
Joined: 20 Aug 2021 08:07

Re: How to make a custom mouse cursor in batch?

#12 Post by back_slash » 28 Aug 2021 09:20

@ShadowThief


Well, are there any tricks in the WIN32 api or C++ for this?
Again, I can't code in C++ or use the Win32 Api.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How to make a custom mouse cursor in batch?

#13 Post by penpen » 28 Aug 2021 13:20

You might hook into an actual process which uses a console window, create a custom subclass overloading the actual "OnSetCursor()" function and replace the actual console instance with its subclass.
But I'm pretty sure, that is highly risky, as you have no idea if someone else had the same idea and already changed the associated windows object; if you don' want to have an unstable window, you need to create a subclass of that specific object (and can't use the typical CWnd object).
Beside that, such kind of stuff windows usually is pretty well protected against so you probably need to have at least admin rights if not system rights.

See https://docs.microsoft.com/en-us/troubl ... e-method-1.
You should get the console window by doing:

Code: Select all

   HWND  hConsoleWnd = NULL;
   if (AttachConsole(ATTACH_PARENT_PROCESS)) {
      hConsoleWnd = GetConsoleWindow();
      FreeConsole();
   } else {
      return 1;
   }
But i actually can't remember how to get a subclass of an already compiled and running window (i haven't seen that for ages and only for windows XP, so i even can't be sure if that's still possible in windows 10 - but i would guess it).
Maybe your question could better be answered in a c++ forum (for example microsoft, stackoverflow or similar.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to make a custom mouse cursor in batch?

#14 Post by aGerman » 30 Aug 2021 11:45

I prototyped a proof of concept.
Have fun :)

Steffen
Attachments
fullblockmouse.zip
(9.25 KiB) Downloaded 604 times
Last edited by aGerman on 19 Sep 2021 07:20, edited 10 times in total.
Reason: work around missing mouse pointer on taskbar area which covers the console window

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How to make a custom mouse cursor in batch?

#15 Post by Aacini » 30 Aug 2021 13:00

@ aGerman, it works! :D

However, sometimes the cursor leaves behind it a trace of vertical lines 1 pixel wide from the right side of the block cursor. Windows 10 here

Antonio

Post Reply