{"id":1257,"date":"2015-01-06T12:38:59","date_gmt":"2015-01-06T11:38:59","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=1257"},"modified":"2015-01-06T12:38:59","modified_gmt":"2015-01-06T11:38:59","slug":"java-parsing-given-string-to-be-used-by-java-awt-robot","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=1257","title":{"rendered":"JAVA &#8211; Parsing given string to be used by java.awt.robot"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"897\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=897\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/eclipse.png\" data-orig-size=\"44,42\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Java\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/eclipse.png\" class=\"size-full wp-image-897 alignleft\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/eclipse.png\" alt=\"Java\" width=\"44\" height=\"42\" \/>Java Robot can be very usefull tool emulating e.g. pressing a key on your keyboard. Sometimes this can be difficult especially for non-standard characters like &#8216;asterisk&#8217;. Therefore I developed following piece of code which translates given string into separated chars, converts them to ASCII and Java Robot types them using ALT+ASCII_KEY<!--more--><\/p>\n<pre lang=\"java\">\/\/ The purpose is to translate given string to sparated characters \r\n\/\/ which are typed one by one using their corresponding ASCII value\r\n\/\/ This value is then translated to KeyCodes \r\n\/\/ VK_NUMPAD0 - VK_NUMPAD9 (96 - 105)\r\nprivate void TypeString(String data){\r\n\/\/ Example data: data = \"Hello World\"\r\n\/\/ First loop: c = 'H'\r\n  for (char c : data.toCharArray()){\t\t\r\n\/\/  ASCII code for 'H': charcode_int = 72\r\n    int charcode_int = (int)c;\r\n\t\t\t\r\n\/\/  charcode = \"72\"\r\n    String charcode = Integer.toString(charcode_int);\r\n    robot.keyPress(KeyEvent.VK_ALT);\r\n\t\t\t\r\n\/\/  First loop: ascii_c = '7'\r\n    for (char ascii_c : charcode.toCharArray()){\r\n\/\/    ascii_n = 103 (= VK_NUMPAD7)\r\n      int ascii_n = Integer.parseInt(String.valueOf(ascii_c)) + 96;\t\t\t\t\t\r\n      robot.keyPress(ascii_n);\r\n      robot.keyRelease(ascii_n);\r\n    }\r\n\t\t\t\r\n    robot.keyRelease(KeyEvent.VK_ALT);\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Java Robot can be very usefull tool emulating e.g. pressing a key on your keyboard. Sometimes this can be difficult especially for non-standard characters like &#8216;asterisk&#8217;. Therefore I developed following piece of code which translates given string into separated chars, &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=1257\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"JAVA - Parsing given string to be used by java.awt.robot","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,9,10,5],"tags":[24,444,378],"class_list":["post-1257","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-development","category-java","category-tools","tag-ascii","tag-java","tag-robot"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-kh","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1257"}],"version-history":[{"count":1,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1257\/revisions"}],"predecessor-version":[{"id":1258,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1257\/revisions\/1258"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}