{"id":4967,"date":"2014-06-13T21:49:30","date_gmt":"2014-06-14T01:49:30","guid":{"rendered":"http:\/\/nycphantom.com\/journal\/?p=4967"},"modified":"2014-06-13T21:49:30","modified_gmt":"2014-06-14T01:49:30","slug":"auto-text-highlighter","status":"publish","type":"post","link":"https:\/\/nycphantom.com\/journal\/?p=4967","title":{"rendered":"Auto Text Highlighter"},"content":{"rendered":"<p>My AutoTextHighlighter app in C# gave me trouble for a little while when I use it in Windows 7 desktop. Was I using Vista before?<\/p>\n<p><strong>Short story version:<\/strong><\/p>\n<p>1. http:\/\/stackoverflow.com\/questions\/2346281\/vb-net-sendkeys-letters-duplicate<\/p>\n<p>2. http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.sendkeys.sendwait.aspx<\/p>\n<p>3. http:\/\/msdn.microsoft.com\/en-us\/library\/ms184658.aspx<\/p>\n<p>4. Be sure to keep the app.config (*.exe.config) file next to the exe app.<\/p>\n<p><strong>Long Story version:<\/strong><\/p>\n<p>SendKeys.SendWait was doing unpredictable repeats ({ENTER} key). It turns out Microsoft was aware of it and blames it on .NET Framework 3.0 timing issues. Before this, I had lost the latest source code for my application due to Desktop HDD reformat\/upgrade. So I used<a href=\"http:\/\/www.jetbrains.com\/decompiler\/\" target=\"_blank\"> JetBrain dotPeek<\/a> to disassemble my exe file. After that, there was a Callback issue with \"garbage collected delegate...invoke\" stuff. I had no idea and no time. So I fixed it via <a href=\"http:\/\/www.codeproject.com\/Articles\/19004\/A-Simple-C-Global-Low-Level-Keyboard-Hook\" target=\"_blank\">comments <\/a>on the site of the globalkeyboardhook script:<\/p>\n<p><em>you have no reference of the callback-method.<\/em><br \/>\n<em>\u00a0 After:<\/em><br \/>\n<em><span class=\"code-keyword\">public<\/span> <span class=\"code-keyword\">delegate<\/span> <span class=\"code-keyword\">int<\/span> keyboardHookProc(<span class=\"code-keyword\">int<\/span> code, <span class=\"code-keyword\">int<\/span> wParam, <span class=\"code-keyword\">ref<\/span> keyboardHookStruct lParam);<\/em><br \/>\n<em>just add a new line with:<\/em><br \/>\n<em><span class=\"code-keyword\">private<\/span> keyboardHookProc _keyboardHookProc;<\/em><br \/>\n<em> And in function \"hook\" you have to change code to:<\/em><br \/>\n<em>hInstance = LoadLibrary(<span class=\"code-string\">\"<\/span><span class=\"code-string\">User32\"<\/span>); _keyboardHookProc = <span class=\"code-keyword\">new<\/span> keyboardHookProc(hookProc); hhook = SetWindowsHookEx(WH_KEYBOARD_LL, _keyboardHookProc, hInstance, <span class=\"code-digit\">0<\/span>);<\/em><\/p>\n<p>Then, the source code is fully back. To fix the SendKeys.SendWait issue, I have to add:<br \/>\n<code><span class=\"pun\">&lt;<\/span><span class=\"pln\">appSettings<\/span><span class=\"pun\">&gt;<br \/>\n<\/span><span class=\"pun\">&lt;<\/span><span class=\"pln\">add key<\/span><span class=\"pun\">=<\/span><span class=\"str\">\"SendKeys\"<\/span><span class=\"pln\"> value<\/span><span class=\"pun\">=<\/span><span class=\"str\">\"SendInput\"<\/span><span class=\"pun\">\/&gt;<br \/>\n<\/span><span class=\"pun\">&lt;\/<\/span><span class=\"pln\">appSettings<\/span><span class=\"pun\">&gt;<\/span><\/code><\/p>\n<p>to my app.config file. This is in the Solution Explorer -&gt; program name-&gt; app.config. Just before the text &lt;\/configuration&gt;.<\/p>\n<p>After the build, in bin folder, there is another *.exe.config file which is the same as app.config. I made sure both exe and exe.config files are together. Perhaps it could release both files as one single exe file, but I don't have time to find that out now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My AutoTextHighlighter app in C# gave me trouble for a little while when I use it in Windows 7 desktop. Was I using Vista before? Short story version: 1. http:\/\/stackoverflow.com\/questions\/2346281\/vb-net-sendkeys-letters-duplicate 2. http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.sendkeys.sendwait.aspx 3. http:\/\/msdn.microsoft.com\/en-us\/library\/ms184658.aspx 4. Be sure to keep the &hellip; <a href=\"https:\/\/nycphantom.com\/journal\/?p=4967\">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":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-4967","post","type-post","status-publish","format-standard","hentry","category-technical"],"_links":{"self":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/4967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4967"}],"version-history":[{"count":1,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/4967\/revisions"}],"predecessor-version":[{"id":4968,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/4967\/revisions\/4968"}],"wp:attachment":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}