Jump to content

Alternate (Shift) Character of a Key


 Share

Recommended Posts

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...

Link to comment
Share on other sites

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...