{"id":62,"date":"2007-05-11T21:19:26","date_gmt":"2007-05-11T19:19:26","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/postkey32ex\/"},"modified":"2007-05-11T21:19:27","modified_gmt":"2007-05-11T19:19:27","slug":"postkey32ex","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/postkey32ex\/","title":{"rendered":"PostKey32ex"},"content":{"rendered":"<p><em>>  I have build an application who displays a hebrew keyboard, and I use<br \/>\n>  a combination of six TToolBars with left or right click mouse events<br \/>\n> for displaying 153 possible characters.<br \/>\n><br \/>\n>  The following lines (with *key* as character code)<br \/>\n><br \/>\n>  keybd_event( key, MapVirtualKey( key, 0), 0, 0 );<br \/>\n>  keybd_event( key, MapVirtualKey( key, 0), KEYEVENTF_KEYUP, 0 );<br \/>\n><br \/>\n>  don&#8217;t permit the display of each possible characters, because the code<br \/>\n>  character range is 33..227 and some keys are reserved by the system.<br \/>\n>  Is it a way to bypass the problem and display all the characters<br \/>\n>  I need ?<\/em><\/p>\n<p>The SendText function below should be able to manufacture the correct keyboard events for each character. But this requires that the current thread locale is hebrew and a hebrew keyboard layout has been activated (see ActivateKeyboardLayout).<\/p>\n<p>[code lang=&#8221;delphi&#8221;]{************************************************************<br \/>\n* Procedure PostKeyEx32<br \/>\n*<br \/>\n* Parameters:<br \/>\n*  key    : virtual keycode of the key to send. For printable<br \/>\n*          keys this is simply the ANSI code (Ord(character)).<br \/>\n*  shift  : state of the modifier keys. This is a set, so you<br \/>\n*          can set several of these keys (shift, control, alt,<br \/>\n*          mouse buttons) in tandem. The TShiftState type is<br \/>\n*          declared in the Classes Unit.<br \/>\n*  specialkey: normally this should be False. Set it to True to<br \/>\n*          specify a key on the numeric keypad, for example.<br \/>\n* Description:<br \/>\n*  Uses keybd_event to manufacture a series of key events matching<br \/>\n*  the passed parameters. The events go to the control with focus.<br \/>\n*  Note that for characters key is always the upper-case version of<br \/>\n*  the character. Sending without any modifier keys will result in<br \/>\n*  a lower-case character, sending it with [ssShift] will result<br \/>\n*  in an upper-case character!<br \/>\n*Created: 17.7.98 by P. Below<br \/>\n************************************************************}<br \/>\nProcedure PostKeyEx32( key: Word; Const shift: TShiftState;<br \/>\n                    specialkey: Boolean );<br \/>\n  Type<br \/>\n    TShiftKeyInfo = Record<br \/>\n                      shift: Byte;<br \/>\n                      vkey : Byte;<br \/>\n                    End;<br \/>\n    byteset = Set of 0..7;<br \/>\n  Const<br \/>\n    shiftkeys: Array [1..3] of TShiftKeyInfo =<br \/>\n      ((shift: Ord(ssCtrl); vkey: VK_CONTROL ),<br \/>\n      (shift: Ord(ssShift); vkey: VK_SHIFT ),<br \/>\n      (shift: Ord(ssAlt); vkey: VK_MENU ));<br \/>\n  Var<br \/>\n    flag: DWORD;<br \/>\n    bShift: ByteSet absolute shift;<br \/>\n    i: Integer;<br \/>\n  Begin<br \/>\n    For i := 1 To 3 Do Begin<br \/>\n      If shiftkeys[i].shift In bShift Then<br \/>\n        keybd_event( shiftkeys[i].vkey,<br \/>\n                    MapVirtualKey(shiftkeys[i].vkey, 0),<br \/>\n                    0, 0);<br \/>\n    End; { For }<br \/>\n    If specialkey Then<br \/>\n      flag := KEYEVENTF_EXTENDEDKEY<br \/>\n    Else<br \/>\n      flag := 0;<\/p>\n<p>    keybd_event( key, MapvirtualKey( key, 0 ), flag, 0 );<br \/>\n    flag := flag or KEYEVENTF_KEYUP;<br \/>\n    keybd_event( key, MapvirtualKey( key, 0 ), flag, 0 );<\/p>\n<p>    For i := 3 DownTo 1 Do Begin<br \/>\n      If shiftkeys[i].shift In bShift Then<br \/>\n        keybd_event( shiftkeys[i].vkey,<br \/>\n                    MapVirtualKey(shiftkeys[i].vkey, 0),<br \/>\n                    KEYEVENTF_KEYUP, 0);<br \/>\n    End; { For }<br \/>\n  End; { PostKeyEx32 }<\/p>\n<p>Procedure SendText( S: String );<br \/>\n  Procedure SendRawCharacter( ch : Char );<br \/>\n    Var<br \/>\n      i: Integer;<br \/>\n      numStr: String;<br \/>\n    Begin<br \/>\n      numStr := Format(&#8216;%4.4d&#8217;,[Ord(ch)]);<br \/>\n      keybd_event( VK_MENU, MapVirtualKey(VK_MENU, 0),<br \/>\n                  0, 0);<br \/>\n      for i:= 1 to Length(numStr) do<br \/>\n        PostKeyEx32( VK_NUMPAD0 + Ord(numstr[i])-Ord(&#8216;0&#8217;), [], false );<br \/>\n      keybd_event( VK_MENU, MapVirtualKey(VK_MENU, 0),<br \/>\n                  KEYEVENTF_KEYUP, 0);<br \/>\n    End;<\/p>\n<p>  Var<br \/>\n    flags: TShiftState;<br \/>\n    vcode: word;<br \/>\n    ret  : word;<br \/>\n    i, n : Integer;<br \/>\n    mask : word;<br \/>\n  Begin { SendText }<br \/>\n    For i := 1  To Length(S) Do Begin<br \/>\n      ret := VkKeyScan( S[i] );<br \/>\n      If ret = $FFFF Then<br \/>\n        SendRawCharacter( S[i] )<br \/>\n      Else Begin<br \/>\n        vcode := Lobyte( ret );<br \/>\n        flags := [];<br \/>\n        mask  := $100;<br \/>\n        For n := 1 To 3 Do Begin<br \/>\n          If (ret and mask) <> 0 Then Begin<br \/>\n            Case mask Of<br \/>\n              $100: Include( flags, ssShift );<br \/>\n              $200: Include( flags, ssCtrl );<br \/>\n              $400: Include( flags, ssAlt );<br \/>\n            End; { Case }<br \/>\n          End; { If }<br \/>\n          mask := mask shl 1;<br \/>\n        End; { For }<br \/>\n        PostKeyEx32( vcode, flags, false );<br \/>\n      End; { Else }<br \/>\n    End; { For }<br \/>\n  End; { SendText }<br \/>\n[\/code] <\/p>\n<p>Peter Below (TeamB)<\/p>\n<p>[tags]Delphi, API[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>> I have build an application who displays a hebrew keyboard, and I use > a combination of six TToolBars with left or&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[84,75],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-10","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/62"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}