We can use GetKeyNameText() to retrieve a string that represents the name of a key. Is there any way to do the reverse, ie get a scancode or virtual key for a given key name?
I want to write key names to a config file so users can edit them easily. When I read in the config file, I would need to do the reverse of GetKeyNameText().
Not a good idea, these names are not constant:
The key name is translated according to the layout of the currently installed keyboard, thus the function may give different results for different input locales.
If you are desperate I suppose you can call GetKeyNameText in a loop trying all possible scancodes.
MapVirtualKey can convert a scancode to a virtual key if you also need to do that. Virtual keys are stable across all keyboards and all versions of Windows.
I would suggest that you hardcode some of the names that are common and have virtual keys like A-Z, 0-9, Ctrl, Alt, Shift, Home, Insert etc. and store those as English text. Only store the scancode for other strange keys.
Related
Basically, I want readline to recognize cursor keys for me. Their byte identifiers are multi-character, like e.g. \e[D. So hooking up to rl_getc isn't enough. However, I didn't see any variables similar to rl_key_sequence or rl_current_key_seq, etc.…
Is there really no way to get the – one have to say: fully processed and utilized information, i.e.: the multibyte key ID – out of readline?
I'm working on a project in which a user can search on a product table.
But the problem is the user can set their keyboard layout in Arabic or Persian (as the user preferred), as you may know, Arabic and Persian have common chars except in a few chars like (ك and ک) or (ي and ی) and so on (these letters have the same meaning but different writting).
Now I want the database to return the same result for both letters ك and ک because these two letters have the same meaning with different writing.
Because these two characters have different ASCII then by default Postgres doesn't treat them as the same.
Some solutions are:
Replace the letters before comparation (Has performance issue).
Make the database unification for these letters (It needs a job to do unification).
Use a custom function in the database to compare the criteria (I should aware to use the function anywhere I want to search data).
Use Postgres TRANSLATE function on the query (same as cases 1 and 3).
Is there any other solution to make Postgres treat ك and ک as the same character?? (maybe with custom collation or dictionary)
Looking an example source code wasn't enough, and I couldn't find any official documentation about theKbdLayerDescriptorsymbol. So I have still some questions about it :
What is the purpose of the ligature table, or more precisely how does it works. Is it for writing pre‑composed characters ? If not, does it means automatically insert the ZERO WIDTH JOINER character, or it simply write several characters without ligature ?
Is is possible to define three or more shift states with keys of the numeric pad ?
I saw theKBD_TYPEneed to be defined. What are the purpose of each integer values ?
Is it possible to use Unicode values larger than 16 bits like the mathematical𝚤 ?
I saw keyboards layout use[HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout\DosKeybCodes]and[HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layouts]but it seems it is not the only registry keys that need to be completed in order to register a system wide keyboard. So what are the required registry keys for installing a system wide keyboard layout ?
If I create a named key for use in Google AppEngine, what kind of String is the key-name? Does it use Unicode characters or is it a binary string?
More specifically, if I want to have my key-name made up of 8-bit binary data, is there a way I can do it? If not, can I at least use 7-bit binary data? Or are there any reserved values? Does it use NULL as the End-Of-String marker, for example?
GAE docs do not specify any restrictions on the key-name String. So a String with any content should be valid.
If you want to use a binary data as an identifier, then you should encode it into a String. You can use any of the binary-to-text encoding methods: most used seem to be Base64 (3 bytes = 4 chars) and BinHex (1 byte = 2 chars).
I meanwhile had some time to actually test this out by generating a bunch of keys with binary names and then performing a kind-only query to get all the keys back. Here are the results:
Any binary character is fine. If you create an entity with key name "\x00\x13\x127\x255", a query will find this entity and its key name will return that same string
The AppEngine Dashboard, Database Viewer, and other tools will simply omit characters that aren't displayable, so the key names "\x00test" and \x00\x00test will both show up as separate entities, but their keys are both shown as "test"
I have not tested all available AppEngine tools, just some of the basics in the Console, so there may be other tools that get confused by such keys...
Keys are UTF-8 encoded, so any character between 128 and 255 takes up 2 bytes of storage
From this, I would derive the following recommendations:
If you need to be able to work with individual entities from the AppEngine console and need to identify them by key, you are limited to printable characters and thus need to encode the binary key name into a String either in Base16 (hex; 50% overhead), Base64 (33% overhead), or Base85 (25% overhead)
If you don't care about key readability, but need to pack as much data as possible into the key name with minimal storage use, use Base128 encoding (i.e. 7-bits only; 14% overhead) to avoid the implicit UTF-8 encoding (50% overhead!) of 8-bit data data
Asides:
I will accept #PeterKnego's answer instead of this one since this one basically only confirms and expands on what he already assumed correctly.
From looking through the source code of the Java API, I think that the UTF-8 encoding of the key-name happens in the API (while building the protocol buffer) rather than in BigTable, so if you really want to go nuts on storage space maximization, it may be possible to build your own protocol buffers and store full 8-bit data without overhead. But this is probably asking for trouble...
i need to generate unique values by using ipv4 and ipv6 addresses i.e if i input 192.37.4.60; a unique key should be generated and when i enter 192.60.4.37 a another key should be generated. How can i do this can any one help me out and i can also input ipv6 address also how to generate unique values to each input. can any one propse any algorithm or any present algorithm
Convert the IP into its numerical (decimal) representation:
10.0.0.1 -> 00001010 00000000 00000000 00000001 -> 167772161
This is how a lot of IP addresses are stored internally. It's nice because it only requires 32 bits of storage. You can do this for IPv6 too, but it's going to require something bigger than a uint32.
The IPs are pretty unique :) Especially IPv6 addresses.
Also, you can always use a hash algorithm (e.g. MD5, SHA1 etc.) to create a "key". It will be unique, as long as the input data is also unique :)
Output the input IP address: voilà, requirements met!
(If my solution doesn't work for you, it means you need to add more details to your question)
one possible solution can be to use left shift operator and add. For example if a, b, c and d represent the octets then following code will give you a unique value
int a=1;
int b=2;
int c=3;
int d=4;
int value =(a<<24)+(b<<16)+(c<<8)+d;
There are a couple of solution possible depending of what are the needs of your problem.
You could use the IP address themselves, but keep in mind that an IP address can be spoofed.
If you intend to use this key amongst multiple peers in order to secure a communication channel, then you might want to take a look towards the symmetric-key or public-key algorithms
If you only want to use them for some static data you can use either of these : MD5, AES and SHA*.
You might want to look to use multiple source for your algorithm. Consider using, in combination with the MAC address, any other material-related information that you can obtain from the machine/client on which the application will run
You don't state any required properties of the keys excet that thy should be unique, so the obvious solution is to use the canonicalized IP addresses as keys. You can turn the addresses into numbers the obvious way, but be warned that IPv6 addresses make for huge numbers, so you'll need the BigInt implementation in whatever language you use.
(If you didn't actually mean that all 340 undecillion addresses should have unique keys, then of course you should look at normal hash functions instead.)
Another option can be to use the inet_pton directly.