VOGONS


First post, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

Probably everyone knows this already (and, if so, I apologize for wasting bandwidth), but I finally figured out that it's possible to use the Cmd key in OS X (which is presumably the same as the Win key in Windows) in the hard-coded key assignments in DOSBox (the MAPPER_AddHandler instructions, if that's the right word for it).

But I've come across a problem that I hope someone can help with.

First, in order to hardcode the OS X Cmd key (again, though I haven't tested it, presumably the same as the Win key), I added this line near the foot of mapper.h:

#define MMOD3 0x8

Then, in various files in the source code, I replaced MMOD1|MMOD2 and other MMOD1 or MMOD2 assignments with MMOD3. This seems to work in every case, except in sdlmain.cpp, where I tried this:

MAPPER_AddHandler(SwitchFullScreen,MK_return,MMOD3,"fullscr","Fullscreen");

The result was that in the compiled executable, every time I pressed Enter, DOSBox would toggle between fullscreen and windowed mode. That doesn't happen if I use MMOD1 or MMOD2. Does anyone know a way to fix this?

One possibly relevant detail: Before I figured out how to hard-code the Cmd key, I was using a keyboard mapper file that let me assign Cmd-Return, Cmd-F10, etc., by adding these lines:

hand_fullscr "key 13 mod3" 
....
mod_3 "key 309" "key 310"

This worked perfectly, so I can't figure out why MK_return,MMOD3 acts like plain MK_return when hard-coded.

Thanks for any and all help with this.

Reply 1 of 13, by truth_deleted

User metadata
emendelson wrote:
use the Cmd key in OS X […]
Show full quote

use the Cmd key in OS X

mapper.h:
#define MMOD3 0x8

MAPPER_AddHandler(SwitchFullScreen,MK_return,MMOD3,"fullscr","Fullscreen");

The result was that in the compiled executable, every time I pressed Enter, DOSBox would toggle between fullscreen and windowed mode. That doesn't happen if I use MMOD1 or MMOD2. Does anyone know a way to fix this?

Perhaps try this addition to CreateDefaultBinds (in sdl_mapper.cpp):
sprintf(buffer,"mod_3 \"key %d\"",SDLK_LMETA);CreateStringBind(buffer);

Reply 2 of 13, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
truth5678 wrote:

Perhaps try this addition to CreateDefaultBinds (in sdl_mapper.cpp):
sprintf(buffer,"mod_3 \"key %d\"",SDLK_LMETA);CreateStringBind(buffer);

Thank you! I added these two lines immediately below the similar lines for the LALT, etc. keys:

sprintf(buffer,"mod_3 \"key %d\"",SDLK_LMETA);CreateStringBind(buffer);
sprintf(buffer,"mod_3 \"key %d\"",SDLK_RMETA);CreateStringBind(buffer);

Probably uselessly, I also added this line to the list of DefaultKeys:

  {"lmeta",SDLK_LMETA},           {"rmeta",SDLK_RMETA},

Unfortunately, every time I pressed Enter, DOSBox still toggled between fullscreen and a window. Again, all the other MMOD3 assignments work correctly.

So this is still puzzling!

Reply 3 of 13, by truth_deleted

User metadata

Can you bind the function to a key other than Enter? If so, then the particular key press may be coded in OSX (or possibly even SDL, but I hadn't seen evidence of it).

Reply 4 of 13, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
truth5678 wrote:

Can you bind the function to a key other than Enter? If so, then the particular key press may be coded in OSX (or possibly even SDL, but I hadn't seen evidence of it).

Thank you for this: as soon as I tried it, I realized that I can't use MMOD3 at all, because EVERY function that I link to Cmd-keystroke gets performed when I press that keystroke alone. So that If I assign SwitchFullScreen or capture-mouse to Cmd-F3, then every time I press F3, I get the full-screen toggle, or capture the mouse (depending of course on what I assigned). I didn't see this happening before because my build doesn't display cycles etc. in the title bar, but it definitely does happen.

This problem does not occur when I assign a Cmd-keystroke with the keyboard mapper, only when I hard code it into the executable. It also does not occur if I hard-code a function to Cmd-Opt or Cmd-Ctrl instead of simply to Cmd.

This is all very strange - thank you again for helping me make sense of what's happening here. But it would still be nice to be able to hardcode the Cmd key...

Reply 5 of 13, by truth_deleted

User metadata

I can't test this because I don't have dosbox on OSX, but these are changes I would try first.

In sdl_mapper.cpp, there are the following comments:
"dosbox uses LMETA only for
* hotkeys, it's not really mapped to an emulated key"
"dosbox uses RMETA only for hotkeys, it's
* not really mapped to an emulated key"
Therefore, may have to remove use of LMETA and RMETA as hotkeys in sdlmain.cpp; this may help if other code hasn't used these as hotkeys only.

Also, there is another place to enter LMETA or RMETA in sdl_mapper.cpp:
/* Last Row */
AddKeyButtonEvent(PX(0) ,PY(5),BW*2,BH,"CTRL","lctrl",KBD_leftctrl);
AddKeyButtonEvent(PX(3) ,PY(5),BW*2,BH,"ALT","lalt",KBD_leftalt);
AddKeyButtonEvent(PX(5) ,PY(5),BW*6,BH,"SPACE","space",KBD_space);
AddKeyButtonEvent(PX(11),PY(5),BW*2,BH,"ALT","ralt",KBD_rightalt);
AddKeyButtonEvent(PX(14),PY(5),BW*2,BH,"CTRL","rctrl",KBD_rightctrl);

Maybe something like this?
AddKeyButtonEvent(PX(14),PY(5),BW*2,BH,"LMETA","lmeta",KBD_leftmeta);
PX(14) would be updated with a new array element and then the for loop updated to enumerate this element.

And then add "KBD_leftmeta" to keyboard.cpp and keyboard.h.

Reply 6 of 13, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

No luck, I'm afraid, but thank you again.

I followed your instructions, but I had to improvise in keyboard.cpp, where I added these lines:

 case KBD_leftmeta:extend=true;ret=125;break;
case KBD_rightmeta:extend=true;ret=126;break;

The numbers were the ones I found on the web on pages where the other numbers seemed to match the ones already in the file.

As before, any time I pressed return, I got the full-screen toggle. Unless you have an inspiration, I don't think this is worth more of your time. It may not be solvable at all with SDL under OS X!

Reply 7 of 13, by truth_deleted

User metadata

At least the problem is fully documented. If I had an OSX box, I would try additional code edits, especially in SDL. Perhaps you can bind the Alt or Ctrl key instead, for now, and find sufficient functionality.

Reply 8 of 13, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

Ctrl-Alt do work well, and I was trying to bind the Cmd key mostly for consistency with other OS X apps. I'll see if I can do anything in SDL, but, as you can see, I'm trying to do things without understanding what I'm doing! Thanks again for your patience in suggesting all this. I'll report if I make any progress.

Reply 9 of 13, by truth_deleted

User metadata

I wonder if this code would help. Note this is a combination of existing code and two additional lines. It may also help to start with a SVN copy, otherwise the past code additions may interfere.

#if defined (MACOSX)			
case SDL_KEYDOWN:
case SDL_KEYUP:
/* On macs CMD-Q is the default key to close an application */
if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
KillSwitch(true);
else if(event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
SwitchFullScreen(true);
break;
}
#endif

Reply 10 of 13, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
truth5678 wrote:
[…]
Show full quote
#if defined (MACOSX)			
case SDL_KEYDOWN:
case SDL_KEYUP:
/* On macs CMD-Q is the default key to close an application */
if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
KillSwitch(true);
else if(event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
SwitchFullScreen(true);
break;
}
#endif

Again, I'm very grateful to you for taking time over this, but I can easily live without a solution - so I don't want you to feel any obligation to do any more. I don't think this suggestion worked, but the results may be of interest.

I started with a fresh copy of SVN. I added in the code above, but got errors that reminded me that I had to add this to mapper.sh:

#define MMOD3 0x8

Then I added in your suggested code, but got an error message that said I needed to add "}" before else, like this:

#if defined (MACOSX)
case SDL_KEYDOWN:
case SDL_KEYUP:
/* On macs CMD-Q is the default key to close an application */
if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
KillSwitch(true); } /* closing } added here */
else if(event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
SwitchFullScreen(true);
break;
}
#endif

I bound Capture Mouse to Cmd-F10 and FullScreen to Cmd-Return (MK_return,MMOD3). The result, as before, was that if I pressed F10 alone (without Cmd), then the mouse got captured, and if I pressed Return alone (without Cmd) then DOSBox toggled to or from full-screen - the same problem I noticed earlier with binding to Cmd.

BUT, if I pressed Cmd-Return, then the screen briefly toggled from windowed to fullscreen AND back again (or from fullscreen to windowed and back again) - exactly as if I had pressed Cmd-Return twice.

Again, I'm a bit embarrassed at taking so much of your time over this. It would be nice to be able to hard-code handlers to the Cmd key in OS X (and presumably to the Win key in Windows), but Ctrl-Alt does the job extremely well already, and I'm only asking for a luxury, not a necessity. Thank you again for all your help here and in other threads.

Reply 11 of 13, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

shouldn't MOD3 be equal to 4 instead of 8 ?

Water flows down the stream
How to ask questions the smart way!

Reply 12 of 13, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
Qbix wrote:

shouldn't MOD3 be equal to 4 instead of 8 ?

Yes, and I owe everyone, especially truth5678, a deep apology for wasting their time.

I originally tried 0x4 and thought (mistakenly) that it didn't work, and found 8 on various tables of scan code values.

But I was wrong, and Qbix is right: MMOD3 should be 0x4. And when it is, then the Cmd key can be mapped easily, just as Ctrl or Alt can be mapped.

Presumably this also applies to the Win key, which has the same scan code, but I don't have a Win key on my Windows machine so I can't test it.

Again, I apologize for wasting the time of people who have better things to do than try to sort out my mistakes. I absolutely should have got this right the first time.

Last edited by emendelson on 2013-07-29, 19:40. Edited 1 time in total.