Python change keyboard layout

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

Lex98/py_win_keyboard_layout

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Меняем цвет шрифта при помощи HTML

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Interaction with keyboard layout on windows. Tested only on windows 7 x64 with pywin32 build 220

$ sudo pip install py_win_keyboard_layout 

or clone the repository (no installation required, source files are sufficient):

$ git clone https://github.com/Lex98/py_win_keyboard_layout 

Then check the API docs to see what features are available.

import py_win_keyboard_layout # change foreground window keyboard layout to russian py_win_keyboard_layout.change_foreground_window_keyboard_layout(0x04190419) 

py_win_keyboard_layout.get_foreground_window_keyboard_layout

Returns foreground window keyboard layout as integer

py_win_keyboard_layout.get_foreground_window_keyboard_layout() -> 68748313 - 0x04190419 - russian py_win_keyboard_layout.get_foreground_window_keyboard_layout() -> 67699721 - 0x04090409 - english 

py_win_keyboard_layout.change_foreground_window_keyboard_layout

Change foreground window keyboard layout

  • layout_id=0 : integer Integer containing a locale id, eg 68748313 — 0x04190419 — 0x419 — russian. Default change layout like Ctrl+Shift or Alt+Shift

py_win_keyboard_layout.get_keyboard_layout_list

Returns a tuple of all locale ids currently loaded

py_win_keyboard_layout.get_keyboard_layout_list() -> (68748313, 67699721) 

py_win_keyboard_layout.load_keyboard_layout

  • string_layout_id : string. Hex string containing a locale id, eg «00000409»
  • Flags=0 : int. Combination of win32con.KLF_* constants. See more information in MSDN
KLF_ACTIVATE|KLF_SETFORPROCESS|KLF_REORDER == 0x109 == 265 py_win_keyboard_layout.load_keyboard_layout("00000409", KLF_ACTIVATE|KLF_SETFORPROCESS|KLF_REORDER) py_win_keyboard_layout.load_keyboard_layout("00000409", 0x109) py_win_keyboard_layout.load_keyboard_layout("00000409", 265) 
py_win_keyboard_layout.load_keyboard_layout("00000409") -> 67699721 for english 

Источник

keyboard-switch 0.1.3

Simple script written in Python to change keyboard layout on linux by using setxkbmap.

Ссылки проекта

Статистика

Метаданные

Лицензия: Mozilla Public License 2.0 (MPL 2.0)

Требует: Python >=3.6

Сопровождающие

Классификаторы

Описание проекта

keyboard-switch

Simple, yet effective, script written in Python to change keyboard layout on Linux by using setxkbmap .

Why

Maybe my google-fu failed me. Maybe I didn’t read enough of the IBus , fcitx , xkb-switch documentation. Maybe. But I spent enough time doing so without reaching a satisfying answer as to how to switch layouts using them while also switching mapping options and variants all at the same time. Neither of the mentioned three options allowed to do so AFAIK. So I decided to write this little script.

What it is

It’s a script that you use to switch between registered layouts via CLI.

To register a layout, set yourself to it (via setxkbmap ) and call kbswitch -a , being how you want your layout to be remembered as. keyboard-switch will store the layout’s current model , layout , variant and option list under the name . Next, anytime you will use this script to «switch» to this layout (e.g kbswitch -s ), it will call setxkbmap with the aforementioned registered options.

Usage

usage: kbswitch [-h] [-n] [-p] [-s NAME] [-S N] [-a NAME] [-r NAME] [-R N] [-o FROM TO] [-c] [-l] [-d] [--notify] optional arguments: -h, --help show this help message and exit -a NAME, --add NAME Add/Register current mapping with name NAME -n, --next Next mapping -p, --previous Previous mapping -s NAME, --set NAME Set current mapping to NAME -S N, --set-number N Set current mapping to NUMBER -r NAME, --remove NAME Remove mapping with name NAME -R N, --remove-number N Remove mapping with order N -o FROM TO, --order FROM TO Reorder mapping at place FROM to place TO -c, --current Print current layout -l, --list Lists layouts in order -d, --details Print layouts in order with details --notify Prints change to notification window using libnotify 

Example

Add layout

$ kbswitch -a gb_qwerty $ kbswitch -l +  gb_qwerty
$ kbswitch -a gb_colemak $ kbswitch -l +  gb_qwerty   gb_colemak

Internally, the last mapping is still considered the current one because this program isn’tsynchronized to anything.

Switch layout

Using the last two registered layouts and starting under the gb QWERTY layout.

$ kbswitch -n $ kbswitch -l   gb_qwerty +  gb_colemak

Voilà, switched ! We can also select a layout using it’s name or ID:

$ kbswitch -l   gb_qwerty +  gb_colemak   fr_azerty   fr_colemak $ kbswitch -s fr_colemak $ kbswitch -l   gb_qwerty   gb_colemak   fr_azerty +  fr_colemak

Reorder

$ kbswitch -l   gb_qwerty   gb_colemak   fr_azerty +  fr_colemak $ kbswitch -o   1 (put `fr_azerty` at place 1) $ kbswitch -l   gb_qwerty   fr_azerty   gb_colemak +  fr_colemak

Remove

$ kbswitch -l   gb_qwerty   fr_azerty   gb_colemak +  fr_colemak $ kbswitch -r fr_azerty $ kbswitch -l   gb_qwerty   gb_colemak +  fr_colemak

Print

$ kbswitch -l +  gb_qwerty   gb_colemak   fr_colemak
$ kbswitch -c gb_qwerty  model: pc  layout: gb  variant: extd  options:
$ kbswitch -d gb_qwerty  model: pc  layout: gb  variant: extd  options: gb_colemak  model: pc105  layout: gb variant:  options: misc:extend,lv5:caps_switch_lock,grp:shifts_toggle,compose:menu,misc:cmk_curl_dh fr_colemak  model: pc105  layout: fr variant:  options: misc:extend,lv5:caps_switch_lock,grp:shifts_toggle,compose:menu,misc:cmk_curl_dh

Notification

If you want to have a notification of a layout switch via libnotify , you may add the argument —notify .

Ideas on how to use

Set kbswitch -n —notify as a hotkey in your windows manager config.

# Switch to next keyboard layout using mod + Space bindsym $mod+space exec --no-startup-id kbswitch -n --notify

IBus

If you desperately need IBus , as I do because Telegram doesn’t register dead keys and I type in french; in IBus ‘s Preference > Advanced > Keyboard Layout , check Use system keyboard layout . You will be able to register dead keys with IBus while using the system keyboard set by setxkbmap .

Storage

All registered layouts are stored as JSON strings in $XDG_CONFIG_HOME/keyboard-switch/ , usually being ~/.config/keyboard-switch/ , in the file mappings . The current mapping/layout is saved in the file current in the same directory.

Источник

py_win_keyboard_layout 0.2

Install the [PyPI package](https://pypi.python.org/pypi/py_win_keyboard_layout/):

$ sudo pip install py_win_keyboard_layout

or clone the repository (no installation required, source files are sufficient):

$ git clone https://github.com/Lex98/py_win_keyboard_layout

Then check the [API docs](https://github.com/Lex98/py_win_keyboard_layout#api) to see what features are available.

# change foreground window keyboard layout to russian
py_win_keyboard_layout.change_foreground_window_keyboard_layout(0x04190419)
«`

— [py\_win\_keyboard\_layout.**get\_foreground\_window\_keyboard\_layout**](#py_win_keyboard_layout.get_foreground_window_keyboard_layout)
— [py\_win\_keyboard\_layout.**change_foreground_window_keyboard_layout**](#py_win_keyboard_layout.change_foreground_window_keyboard_layout)
— [py\_win\_keyboard\_layout.**get_keyboard_layout_list**](#py_win_keyboard_layout.get_keyboard_layout_list)
— [py\_win\_keyboard\_layout.**load_keyboard_layout**](#py_win_keyboard_layout.load_keyboard_layout)

Returns foreground window keyboard layout as integer

py_win_keyboard_layout.get_foreground_window_keyboard_layout() -> 68748313 — 0x04190419 — russian
py_win_keyboard_layout.get_foreground_window_keyboard_layout() -> 67699721 — 0x04090409 — english

## py_win_keyboard_layout.**change\_foreground\_window\_keyboard\_layout**
Change foreground window keyboard layout

— layout_id=0 : integer
Integer containing a locale id, eg 68748313 — 0x04190419 — 0x419 — russian
Default change layout like Ctrl+Shift or Alt+Shift

— Returns True if layout is changed

Returns a tuple of all locale ids currently loaded

py_win_keyboard_layout.get_keyboard_layout_list() -> (68748313, 67699721)

— string_layout_id : string.
Hex string containing a locale id, eg «00000409»

— Flags=0 : int. Combination of win32con.KLF_* constants. See more information in [MSDN](https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms646305(v=vs.85).aspx)

KLF_ACTIVATE|KLF_SETFORPROCESS|KLF_REORDER == 0x109 == 265
py_win_keyboard_layout.load_keyboard_layout(«00000409», KLF_ACTIVATE|KLF_SETFORPROCESS|KLF_REORDER)
py_win_keyboard_layout.load_keyboard_layout(«00000409», 0x109)
py_win_keyboard_layout.load_keyboard_layout(«00000409», 265)

— Returns the integer locale id that was loaded

py_win_keyboard_layout.load_keyboard_layout(«00000409») -> 67699721 for english

Источник

Python-сообщество

[RSS Feed]

  • Начало
  • » Python для новичков
  • » Смена раскладки клавиатуры

#1 Сен. 2, 2020 02:08:57

Смена раскладки клавиатуры

Как переключать раскладку клавиатуры с рус на eng ? В идеале универсально для всех платформ, но можно и на виндовс. Гугл и поиск по форуме не дал ничего работающего. Единственное как определить номер раскладки

import ctypes u = ctypes.windll.LoadLibrary("user32.dll") pf = getattr(u, "GetKeyboardLayout") print (pf(0)) 

#2 Сен. 2, 2020 23:09:04

Смена раскладки клавиатуры

побалуйтесь этим

import keyboard as kb kb.press_and_release('shift + alt') 

#3 Сен. 3, 2020 00:07:08

Смена раскладки клавиатуры

import keyboard as kb kb.press_and_release('Win+Space') 

#4 Сен. 3, 2020 00:07:52

Смена раскладки клавиатуры

#5 Сен. 3, 2020 00:20:27

Смена раскладки клавиатуры

#6 Сен. 3, 2020 00:31:50

Смена раскладки клавиатуры

это конечно баловство,но вот

import keyboard as kb import win32api as win # определяет раскладку def get_name_layout(): name = win.GetKeyboardLayoutName() if name == '00000409': return 'en' elif name == '00000419': return 'ru' # меняет раскладку def change_layout(set_lay = None): if set_lay == 'ru' or set_lay == 'en': current_lay = get_name_layout() if current_lay == set_lay: print('ok') else: kb.press_and_release('shift + alt') else: print('переключение по умолчанию') kb.press_and_release('shift + alt') print('ok') change_layout('ru') 

Источник

Оцените статью