INPUT - Capture/release mouse from the command line

Here you can discuss the development of patches.

INPUT - Capture/release mouse from the command line

Postby emendelson » 2015-11-21 @ 19:13

It occurred to me that it might be useful to be able to capture the mouse from the command-line, so that a batch or conf file could capture the mouse, start a game, and release the mouse afterward. I couldn't find any way to do this in the existing code, so I somehow managed to throw together a MOUSECAP command. I don't know anything about programming, so this is probably incompetent, and a real programmer could do it better, but it seems to work. Here's how to do it:

1. In shell.h, add to the list of commands:
Code: Select all
void CMD_MOUSECAP(char * args);


2. In shell_cmds.cpp, add below the list of includes:
Code: Select all
extern void GFX_CaptureMouse(void);
extern bool mouselocked;


3. Also in shell.cmds.cpp, in the cmd_list near the top, add:
Code: Select all
{   "MOUSECAP",   0,         &DOS_Shell::CMD_MOUSECAP,   "SHELL_CMD_MOUSECAP_HELP"},


4. Also in shell.cmds.cpp, among the code for the actual commands, add:
Code: Select all
void DOS_Shell::CMD_MOUSECAP(char * args) {
   HELP("MOUSECAP");
   GFX_CaptureMouse();
      if (mouselocked)
         WriteOut("Mouse captured.\n");
      else
         WriteOut("Mouse released.\n");
}


5. Finally, in shell.cpp, add among the help texts:
Code: Select all
   MSG_Add("SHELL_CMD_MOUSECAP_HELP","Toggle mouse capture.\n");

I hope someone else finds this useful.
Last edited by emendelson on 2015-11-22 @ 02:36, edited 3 times in total.
emendelson
Oldbie
 
Posts: 746
Joined: 2010-2-14 @ 02:00

Re: Capture mouse from the command line

Postby Dominus » 2015-11-21 @ 19:15

Nice one ;)

(Moved to Patches)
User avatar
Dominus
DOSBox Moderator
 
Posts: 7644
Joined: 2002-10-03 @ 09:54
Location: Ludwigsburg

Re: Capture mouse from the command line

Postby emendelson » 2015-11-21 @ 19:16

Thank you!
emendelson
Oldbie
 
Posts: 746
Joined: 2010-2-14 @ 02:00

Re: Capture mouse from the command line

Postby emendelson » 2015-11-21 @ 23:43

And this patch should be used together with the one here, which tells how to add a "Mouse Captured - Ctrl-F10 to release" message to the title bar when the mouse is captured:

viewtopic.php?f=41&t=36780
emendelson
Oldbie
 
Posts: 746
Joined: 2010-2-14 @ 02:00


Return to DOSBox Patches

Who is online

Users browsing this forum: No registered users and 1 guest