Jump to content
Sign in to follow this  
TheONE

Alternate (Shift) Character of a Key

Recommended Posts

TheONE

Hello,

I searched all over, but couldn't express myself in keywords. Just wanted to know how could we get the alternate character of a keyboard key (for the current keyboard layout). This is the one when shift is pressed (such as 'A' for 'a' and '@' for 2). I know I could check the status of shift with _IsPressed and subtract 32 from the character code to get the correct uppercase alphabet (Chr($Keycode - 32)). But what about others? Making a table won't solve my problem because of different keyboard layouts and regional settings.

Please if anybody can take the time to help me out...

Share this post


Link to post
Share on other sites
BrettF

Share this post


Link to post
Share on other sites
FlyinRiz

Maybe:

$str = "abc" & Chr (0xE4) & Chr (0xF6) & Chr (0xFC) & Chr (0xDF)
MsgBox (0, "Lowercase", $str)

MsgBox (0, "Uppercase", StringUpper ($str))

I thought it might, but if you use a symbol like $ (or Chr(0x24)) it stays the same for both.

-Aaron

Share this post


Link to post
Share on other sites
FlyinRiz

Hello,

I searched all over, but couldn't express myself in keywords. Just wanted to know how could we get the alternate character of a keyboard key (for the current keyboard layout). This is the one when shift is pressed (such as 'A' for 'a' and '@' for 2). I know I could check the status of shift with _IsPressed and subtract 32 from the character code to get the correct uppercase alphabet (Chr($Keycode - 32)). But what about others? Making a table won't solve my problem because of different keyboard layouts and regional settings.

Please if anybody can take the time to help me out...

This is probably a very messy way of doing it, BUT I think it would work...if you open the virtual keyboard (which should change based on the selected keyboard layout), and hover over the keys (with Au3Info), it will display the Shift+Key, you could then use that to create a dynamic table at the beginning of your script based on key positions rather than key 'labels'. Again this is all in theory, but it might work.

-Aaron

Share this post


Link to post
Share on other sites
FlyinRiz

Proof of concept (XP SP3)

Run(@systemdir & "\osk.exe")
WinWait("On-Screen Keyboard")
MsgBox(0,"` is:",ControlGetText("On-Screen Keyboard","",17))
MsgBox(0,"1 is:",ControlGetText("On-Screen Keyboard","",18))
MsgBox(0,"2 is:",ControlGetText("On-Screen Keyboard","",19))
MsgBox(0,"3 is:",ControlGetText("On-Screen Keyboard","",20))
MsgBox(0,"4 is:",ControlGetText("On-Screen Keyboard","",21))
MsgBox(0,"5 is:",ControlGetText("On-Screen Keyboard","",22))
MsgBox(0,"6 is:",ControlGetText("On-Screen Keyboard","",23))
MsgBox(0,"7 is:",ControlGetText("On-Screen Keyboard","",24))
MsgBox(0,"8 is:",ControlGetText("On-Screen Keyboard","",25))

-Aaron

Share this post


Link to post
Share on other sites
TheONE

The virtual keyboard, yes, that's a way ;) .

I except there should be a windows API for gettng the keyboard layout. I also care about the fact that dfferent keyboard layouts have different characters for keycodes (Spanish, French and so).

Thanks for the input!

Share this post


Link to post
Share on other sites
BrettF
Richard Robertson

http://msdn.microsoft.com/en-us/library/ms646306%28VS.85%29.aspx

Share this post


Link to post
Share on other sites
Richard Robertson

Sometimes you just have to know what to search for. I had actually read about this function in a technical article recently so it was fresh in my mind. Can't remember what the article was though. Figure that one out.

Share this post


Link to post
Share on other sites
TheONE

The On-Screen Keyboard (osk.exe) has the following calls to "user32.dll"

ActivateKeyboardLayout

AllowSetForegroundWindow

BeginPaint

CheckDlgButton

CheckMenuItem

CheckMenuRadioItem

ChildWindowFromPointEx

CloseDesktop

CloseWindowStation

CreateWindowExW

DefWindowProcW

DestroyWindow

DialogBoxParamW

DispatchMessageW

DrawIconEx

EnableMenuItem

EnableWindow

EndDialog

EndPaint

FindWindowW

GetAsyncKeyState

GetClassInfoW

GetClientRect

GetCursorPos

GetDC

GetDesktopWindow

GetDlgItem

GetForegroundWindow

GetKeyState

GetKeyboardLayout

GetKeyboardType

GetMenu

GetMessageW

GetProcessWindowStation

GetSysColor

GetSystemMetrics

GetThreadDesktop

GetUserObjectInformationW

GetWindowLongW

GetWindowRect

GetWindowThreadProcessId

InvalidateRect

IsIconic

IsWindow

KillTimer

LoadCursorW

LoadIconW

LoadImageW

LoadStringW

MapVirtualKeyExW

MapVirtualKeyW

MessageBoxW

MoveWindow

OpenDesktopW

OpenInputDesktop

OpenWindowStationW

PostMessageW

PostQuitMessage

RegisterClassW

RegisterWindowMessageW

ReleaseCapture

ReleaseDC

ScreenToClient

SendInput

SendMessageW

SetCapture

SetClassLongW

SetCursor

SetForegroundWindow

SetProcessWindowStation

SetThreadDesktop

SetTimer

SetWindowLongW

SetWindowPos

SetWindowRgn

ShowWindow

ToUnicodeEx

TranslateMessage

UpdateWindow

WinHelpW

wsprintfA

wsprintfW

Searching for the functions I landed on this http://blogs.msdn.com/b/michkap/archive/2006/03/23/558658.aspx . The functions that do the trick are highlighted in bold.

Share this post


Link to post
Share on other sites
TheONE

That means it's not as simple as I thought (detecting and handling dead keys and ligatures). Just in case someone looks for what I am trying to do....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.