Пример #1
0
status_t
BKeymap::SetToCurrent()
{
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
	key_map* keys = NULL;
	get_key_map(&keys, &fChars);
	if (!keys)
		return B_ERROR;

	memcpy(&fKeys, keys, sizeof(fKeys));
	free(keys);
	return B_OK;
#else	// ! __BEOS__
	fprintf(stderr, "Unsupported operation on this platform!\n");
	exit(1);
#endif	// ! __BEOS__
}
Пример #2
0
static bool etk_beos_get_byte(int32 modifiers, int32 key_code, char *result)
{
	if(result == NULL || key_code < 0 || key_code >= 128) return false;
	
	key_map *keys = NULL;
	char *chars = NULL;

	get_key_map(&keys, &chars);
	if(keys == NULL || chars == NULL)
	{
		if(keys) free(keys);
		if(chars) free(chars);
		return false;
	}

	int32 offset;
	bool retVal = false;

	if((modifiers & B_SHIFT_KEY) && (modifiers & B_CAPS_LOCK))
			offset = keys->caps_shift_map[key_code];
	else if(modifiers & B_SHIFT_KEY)
		offset = keys->shift_map[key_code];
	else if(modifiers & B_CAPS_LOCK)
		offset = keys->caps_map[key_code];
	else
		offset = keys->normal_map[key_code];

	if(chars[offset] == 1)
	{
		*result = chars[offset + 1];
		retVal = true;
	}

	free(keys);
	free(chars);

	return retVal;
}
Пример #3
0
ModifierKeysWindow::ModifierKeysWindow()
	:
	BWindow(BRect(0, 0, 360, 220), B_TRANSLATE("Modifier keys"),
		B_FLOATING_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
			| B_AUTO_UPDATE_SIZE_LIMITS)
{
	get_key_map(&fCurrentMap, &fCurrentBuffer);
	get_key_map(&fSavedMap, &fSavedBuffer);

	BStringView* keyRole = new BStringView("key role",
		B_TRANSLATE_COMMENT("Role", "As in the role of a modifier key"));
	keyRole->SetAlignment(B_ALIGN_RIGHT);
	keyRole->SetFont(be_bold_font);

	BStringView* keyLabel = new BStringView("key label",
		B_TRANSLATE_COMMENT("Key", "As in a computer keyboard key"));
	keyLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
	keyLabel->SetFont(be_bold_font);

	BMenuField* shiftMenuField = _CreateShiftMenuField();
	shiftMenuField->SetAlignment(B_ALIGN_RIGHT);

	BMenuField* controlMenuField = _CreateControlMenuField();
	controlMenuField->SetAlignment(B_ALIGN_RIGHT);

	BMenuField* optionMenuField = _CreateOptionMenuField();
	optionMenuField->SetAlignment(B_ALIGN_RIGHT);

	BMenuField* commandMenuField = _CreateCommandMenuField();
	commandMenuField->SetAlignment(B_ALIGN_RIGHT);

	fShiftConflictView = new ConflictView("shift warning view");
	fShiftConflictView->SetExplicitMaxSize(BSize(15, 15));

	fControlConflictView = new ConflictView("control warning view");
	fControlConflictView->SetExplicitMaxSize(BSize(15, 15));

	fOptionConflictView = new ConflictView("option warning view");
	fOptionConflictView->SetExplicitMaxSize(BSize(15, 15));

	fCommandConflictView = new ConflictView("command warning view");
	fCommandConflictView->SetExplicitMaxSize(BSize(15, 15));

	fCancelButton = new BButton("cancelButton", B_TRANSLATE("Cancel"),
		new BMessage(B_QUIT_REQUESTED));

	fRevertButton = new BButton("revertButton", B_TRANSLATE("Revert"),
		new BMessage(kMsgRevertModifiers));
	fRevertButton->SetEnabled(false);

	fOkButton = new BButton("okButton", B_TRANSLATE("Set modifier keys"),
		new BMessage(kMsgApplyModifiers));
	fOkButton->MakeDefault(true);

	// Build the layout
	SetLayout(new BGroupLayout(B_VERTICAL));

	float forcedMinWidth = be_plain_font->StringWidth("XXX") * 4;
	keyRole->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));

	BLayoutItem* shiftLabel = shiftMenuField->CreateLabelLayoutItem();
	shiftLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
	BLayoutItem* controlLabel = controlMenuField->CreateLabelLayoutItem();
	controlLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
	BLayoutItem* optionLabel = optionMenuField->CreateLabelLayoutItem();
	optionLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
	BLayoutItem* commandLabel = commandMenuField->CreateLabelLayoutItem();
	commandLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));

	AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_SMALL_SPACING)
		.AddGroup(B_HORIZONTAL)
			.Add(keyRole)
			.Add(keyLabel)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(shiftLabel)
			.Add(shiftMenuField->CreateMenuBarLayoutItem())
			.Add(fShiftConflictView)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(controlLabel)
			.Add(controlMenuField->CreateMenuBarLayoutItem())
			.Add(fControlConflictView)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(optionLabel)
			.Add(optionMenuField->CreateMenuBarLayoutItem())
			.Add(fOptionConflictView)
			.End()
		.AddGroup(B_HORIZONTAL)
			.Add(commandLabel)
			.Add(commandMenuField->CreateMenuBarLayoutItem())
			.Add(fCommandConflictView)
			.End()
		.AddGlue()
		.AddGroup(B_HORIZONTAL)
			.Add(fCancelButton)
			.AddGlue()
			.Add(fRevertButton)
			.Add(fOkButton)
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
	);

	_MarkMenuItems();
	_ValidateDuplicateKeys();

	PostMessage(kMsgHideShowIcons);
}
Пример #4
0
void BamKeysKeyView::GetKeyLabel(BString *keyLabel, int32 keycode, int32 modifiers = 0) {
	switch (keycode) {
		case 0:
			break;
		case B_LEFT_SHIFT_KEY:
		case B_RIGHT_SHIFT_KEY:
			*keyLabel << "Shift";
			break;
		case B_LEFT_COMMAND_KEY:
		case B_RIGHT_COMMAND_KEY:
			*keyLabel << "Alt";
			break;
		case B_LEFT_CONTROL_KEY:
		case B_RIGHT_CONTROL_KEY:
			*keyLabel << "Ctrl";
			break;
		case B_LEFT_OPTION_KEY:
		case B_RIGHT_OPTION_KEY:
			*keyLabel << "Optn";
			break;
		case B_CAPS_LOCK:
			*keyLabel << "Caps Lock";
			break;
		case B_NUM_LOCK:
			*keyLabel << "Num Lock";
			break;
		case B_SCROLL_LOCK:
			*keyLabel << "Scrl Lock";
			break;
		// Numeric keys get special attention if numlock is on when mapping.
		case 0x64: // 0
		case 0x58: // 1
		case 0x59: // 2
		case 0x5a: // 3
		case 0x48: // 4
		case 0x49: // 5
		case 0x4a: // 6
		case 0x37: // 7
		case 0x38: // 8
		case 0x39: // 9
			if (modifiers & B_NUM_LOCK) {
				// Switch the state of the SHIFT_KEY to get the
				// proper mapping for numeric keypad keys.
				if (modifiers & B_SHIFT_KEY) {
					modifiers = modifiers ^ B_SHIFT_KEY;
				} else {
					modifiers = modifiers | B_SHIFT_KEY;
				}
			}
		default:
			// Lookup the key code to resolve it to a char.
			//debugger("getkey");
			key_map *keymap;
			char* chars;
			get_key_map(&keymap, &chars);
			
			int32 charindex;

// If you want to see the actual character created by pressing the combination, then
// use the following 'if' block.
/*			if (modifiers & B_CONTROL_KEY) {
				charindex = keymap->control_map[keycode];
			} else if (modifiers & B_OPTION_KEY &&
		               modifiers & B_CAPS_LOCK &&
		               modifiers & B_SHIFT_KEY) 
		    {
				charindex = keymap->option_caps_shift_map[keycode];
			} else if (modifiers & B_OPTION_KEY &&
			           modifiers & B_CAPS_LOCK)
			{
				charindex = keymap->option_caps_map[keycode];
			} else if (modifiers & B_OPTION_KEY &&
			           modifiers & B_SHIFT_KEY)
			{
				charindex = keymap->option_shift_map[keycode];
			} else if (modifiers & B_OPTION_KEY) {
				charindex = keymap->option_map[keycode];
			} else if (modifiers & B_CAPS_LOCK &&
			           modifiers & B_SHIFT_KEY)
			{
				charindex = keymap->caps_shift_map[keycode];
			} else if (modifiers & B_CAPS_LOCK) {
				charindex = keymap->caps_map[keycode];
			} else if (modifiers & B_SHIFT_KEY) {
				charindex = keymap->shift_map[keycode];
			} else { // I decided to cut the rest of the maps.
				charindex = keymap->normal_map[keycode];
			}
*/
// If you only want the key on the keyboard (the normal_map) then use this.
			charindex = keymap->normal_map[keycode];
			
			int charsize = chars[charindex++];
			switch(charsize) {
				case 0:
					// unmapped
					break;
				case 1:
					*keyLabel << chars[charindex];
					break;
				default:
					char *str = new char[charsize + 1];
					strncpy(str, &(chars[charindex]), charsize);
					*keyLabel << str;
					delete []str;
			}
			free(keymap);
			free(chars);
	}
}
Пример #5
0
/*****************************************************************************
 * VideoWindow::MessageReceived
 *****************************************************************************/
void
VideoWindow::MessageReceived( BMessage *p_message )
{
    switch( p_message->what )
    {
        case SHOW_INTERFACE:
            SetInterfaceShowing( true );
            break;
        case TOGGLE_FULL_SCREEN:
            BWindow::Zoom();
            break;
        case RESIZE_50:
        case RESIZE_100:
        case RESIZE_200:
            if (IsFullScreen())
                BWindow::Zoom();
            _SetVideoSize(p_message->what);
            break;
        case VERT_SYNC:
            SetSyncToRetrace(!IsSyncedToRetrace());
            break;
        case WINDOW_FEEL:
            {
                window_feel winFeel;
                if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
                {
                    SetFeel(winFeel);
                    fCachedFeel = winFeel;
                    if (winFeel == B_FLOATING_ALL_WINDOW_FEEL)
                        fSettings->AddFlags(VideoSettings::FLAG_ON_TOP_ALL);
                    else
                        fSettings->ClearFlags(VideoSettings::FLAG_ON_TOP_ALL);
                }
            }
            break;
        case ASPECT_CORRECT:
            SetCorrectAspectRatio(!CorrectAspectRatio());
            break;

        case B_KEY_DOWN:
        case B_UNMAPPED_KEY_DOWN:
        case B_KEY_UP:
        case B_UNMAPPED_KEY_UP:
        {
            key_map * keys;
            char    * chars;
            int32     key, modifiers;

            if( p_message->FindInt32( "key", &key ) != B_OK ||
                p_message->FindInt32( "modifiers", &modifiers ) != B_OK )
            {
                /* Shouldn't happen */
                break;
            }

            if( ( p_message->what == B_KEY_UP ||
                  p_message->what == B_UNMAPPED_KEY_UP ) &&
                !( modifiers & B_COMMAND_KEY ) )
            {
                /* We only use the KEY_UP messages to detect Alt+X
                   shortcuts (because the KEY_DOWN messages aren't
                   sent when Alt is pressed) */
                break;
            }

            /* Special case for Alt+1, Alt+2 and Alt+3 shortcuts: since
               the character depends on the keymap, we use the key codes
               directly (18, 19, 20) */
            if( ( modifiers & B_COMMAND_KEY ) &&
                key >= 18 && key <= 20 )
            {
                if( key == 18 )
                    PostMessage( RESIZE_50 );
                else if( key == 19 )
                    PostMessage( RESIZE_100 );
                else
                    PostMessage( RESIZE_200 );

                break;
            }

            /* Get the current keymap */
            get_key_map( &keys, &chars );

            if( key >= 128 || chars[keys->normal_map[key]] != 1 )
            {
                /* Weird key or Unicode character */
                free( keys );
                free( chars );
                break;
            }

            vlc_value_t val;
            val.i_int = ConvertKeyToVLC( chars[keys->normal_map[key]+1] );

            if( modifiers & B_COMMAND_KEY )
            {
                val.i_int |= KEY_MODIFIER_ALT;
            }
            if( modifiers & B_SHIFT_KEY )
            {
                val.i_int |= KEY_MODIFIER_SHIFT;
            }
            if( modifiers & B_CONTROL_KEY )
            {
                val.i_int |= KEY_MODIFIER_CTRL;
            }
            var_Set( p_vout->p_libvlc, "key-pressed", val );

            free( keys );
            free( chars );
            break;
        }

        default:
            BWindow::MessageReceived( p_message );
            break;
    }
}
Пример #6
0
void
KeyStrokeSequenceCommandActuator::_GenerateKeyCodes()
{
	int slen = fSequence.Length();
	fKeyCodes = new int32[slen];
	fModCodes = new int32[slen];
	fStates = new uint8[slen * 16];

	memset(fStates, 0, slen * 16);

	key_map* map;
	char* keys;
	get_key_map(&map, &keys);
	for (int i = 0; i < slen; i++) {
		uint32 overrideKey = 0;
		uint32 overrideMods = (uint32)-1;
		for (int32 j = fOverrideOffsets.CountItems()-1; j >= 0; j--) {
			if ((int32)(addr_t)fOverrideOffsets.ItemAt(j) == i) {
				overrideKey= (uint32)(addr_t) fOverrideKeyCodes.ItemAt(j);
				overrideMods = (uint32)(addr_t) fOverrideModifiers.ItemAt(j);
				break;
			}
		}

		uint8* states = &fStates[i * 16];
		int32& modCode = fModCodes[i];
		if (overrideKey == 0) {
			// Gotta do reverse-lookups to find out the raw keycodes for a
			// given character. Expensive--there oughtta be a better way to do
			// this.
			char next = fSequence.ByteAt(i);
			int32 key = _LookupKeyCode(map, keys, map->normal_map, next,
				states, modCode, 0);
			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->shift_map, next, states,
					modCode, B_LEFT_SHIFT_KEY | B_SHIFT_KEY);
			}

			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->caps_map, next, states,
					modCode, B_CAPS_LOCK);
			}

			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->caps_shift_map, next,
					states, modCode,
					B_LEFT_SHIFT_KEY | B_SHIFT_KEY | B_CAPS_LOCK);
			}

			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->option_map, next, states,
					modCode, B_LEFT_OPTION_KEY | B_OPTION_KEY);
			}

			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->option_shift_map, next,
					states, modCode, B_LEFT_OPTION_KEY | B_OPTION_KEY
						| B_LEFT_SHIFT_KEY | B_SHIFT_KEY);
			}

			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->option_caps_map, next,
					states, modCode,
					B_LEFT_OPTION_KEY | B_OPTION_KEY | B_CAPS_LOCK);
			}

			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->option_caps_shift_map,
					next, states, modCode, B_LEFT_OPTION_KEY | B_OPTION_KEY
						| B_CAPS_LOCK | B_LEFT_SHIFT_KEY | B_SHIFT_KEY);
			}

			if (key < 0) {
				key = _LookupKeyCode(map, keys, map->control_map, next, states,
					modCode, B_CONTROL_KEY);
			}

			fKeyCodes[i] = key >= 0 ? key : 0;
		}

		if (overrideMods != (uint32)-1) {
			modCode = (int32)overrideMods;

			// Clear any bits that might have been set by the lookups...
			_SetStateBit(states, map->caps_key, false);
			_SetStateBit(states, map->scroll_key, false);
			_SetStateBit(states, map->num_key, false);
			_SetStateBit(states, map->menu_key, false);
			_SetStateBit(states, map->left_shift_key, false);
			_SetStateBit(states, map->right_shift_key, false);
			_SetStateBit(states, map->left_command_key, false);
			_SetStateBit(states, map->right_command_key, false);
			_SetStateBit(states, map->left_control_key, false);
			_SetStateBit(states, map->right_control_key, false);
			_SetStateBit(states, map->left_option_key, false);
			_SetStateBit(states, map->right_option_key, false);

			// And then set any bits that were specified in our override.
			if (modCode & B_CAPS_LOCK)
				_SetStateBit(states, map->caps_key);

			if (modCode & B_SCROLL_LOCK)
				_SetStateBit(states, map->scroll_key);

			if (modCode & B_NUM_LOCK)
				_SetStateBit(states, map->num_key);

			if (modCode & B_MENU_KEY)
				_SetStateBit(states, map->menu_key);

			if (modCode & B_LEFT_SHIFT_KEY)
				_SetStateBit(states, map->left_shift_key);

			if (modCode & B_RIGHT_SHIFT_KEY)
				_SetStateBit(states, map->right_shift_key);

			if (modCode & B_LEFT_COMMAND_KEY)
				_SetStateBit(states, map->left_command_key);

			if (modCode & B_RIGHT_COMMAND_KEY)
				_SetStateBit(states, map->right_command_key);

			if (modCode & B_LEFT_CONTROL_KEY)
				_SetStateBit(states, map->left_control_key);

			if (modCode & B_RIGHT_CONTROL_KEY)
				_SetStateBit(states, map->right_control_key);

			if (modCode & B_LEFT_OPTION_KEY)
				_SetStateBit(states, map->left_option_key);

			if (modCode & B_RIGHT_OPTION_KEY)
				_SetStateBit(states, map->right_option_key);
		}

		if (overrideKey > 0) {
			if (overrideKey > 127) {
				// invalid value?
				overrideKey = 0;
			}

			fKeyCodes[i] = overrideKey;
			_SetStateBit(states, overrideKey);
		}
	}

	free(keys);
	free(map);
}