Python winreg Keyboard Layout

well hi

i have this code:
import winreg;


def get(name):


      registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,r"Keyboard Layout",0,winreg.KEY_READ);
      value = winreg.QueryValue(registry_key,name);

      return value;

print(get("Keyboard"));

Open in new window


But an error is occured every time i run the programm:FileNotFoundError:[WinError] 2 . My error is when i use string "Keyboard" as a variable to my method:get(name);
LVL 1
Max DestinyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Max

Have you checked there is a registry entry for 'Keyboard' under 'Keyboard Layout'?

When I look there's are 3 entries - 'Preload', 'Substitutes' and 'Toggle', but no 'Keyboard'
0
NorieAnalyst Assistant Commented:
Actually meant 'key' and 'sub-key', couldn't think of the correct terminology earlier.

By the way, you could try using EnumKey from winreg to check all the sub-keys of the 'Keyboard' key.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Max DestinyAuthor Commented:
still need 2 arguments for enum value
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Max DestinyAuthor Commented:
my subkey is correct

i just dont know what string to use as parameter to my method
0
NorieAnalyst Assistant Commented:
Max

The 2nd argument for EnumKey and EnumValue is the index of the key to retrieve.

You can use an integer for that, incrementing it each time you call EnumKey/EnumValue and stopping when you encounter an error.

For example.
def enum_keys(reg):
        if reg:
            keys = []
            try:
                i = 0
                while 1:
                    name = winreg.EnumKey(reg, i)
                    keys.append(name)
                    i += 1
            except WindowsError as e:
                return keys
        else:
            return False 

Open in new window

0
Max DestinyAuthor Commented:
thank u
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.