{"id":983,"date":"2019-06-02T23:06:14","date_gmt":"2019-06-02T14:06:14","guid":{"rendered":"https:\/\/www.oji-koji.com\/?p=983"},"modified":"2021-07-28T10:38:16","modified_gmt":"2021-07-28T01:38:16","slug":"%e3%81%8a%e3%81%be%e3%81%91windows%e7%89%88%e3%81%ae_kbhit%e3%81%a8%e5%90%8c%e3%81%98%e6%a9%9f%e8%83%bd%e3%82%92linux%e3%81%a7%e5%ae%9f%e7%8f%be%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.oji-koji.com\/?p=983","title":{"rendered":"\u304a\u307e\u3051(Windows\u7248\u306e_kbhit\u3068\u540c\u3058\u6a5f\u80fd\u3092Linux\u3067\u5b9f\u73fe\uff1f)"},"content":{"rendered":"\n<p class=\"program_discription\">SimpleClient\u306e\u30e1\u30cb\u30e5\u30fc\u3067Windows\u306fENTER\u30ad\u30fc\u306a\u3057(1\u6587\u5b57\u5165\u529b\u691c\u51fa)\u3067\u52d5\u3044\u3066\u3044\u307e\u3059\u3002<br>Linux\u3067\u3001\u3053\u308c\u3092\u5b9f\u73fe\u3067\u304d\u306a\u3044\u304b\uff1f\u304c\u30c6\u30fc\u30de\u3067\u3059\u3002<br>\u5b9f\u306f\u3001tty(teletypewriter)\u306e\u5c5e\u6027\u3092\u89e6\u308c\u3070\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>tty\u306b\u3064\u3044\u3066\u8efd\u304f\u89e6\u308c\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<br>ssh\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066tty\u3068\u3044\u3046\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>\u6a19\u6e96\u5165\u529b\u3001\u6a19\u6e96\u51fa\u529b\u3068\u306a\u3063\u3066\u3044\u308b\u7aef\u672b\u30c7\u30d0\u30a4\u30b9\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty1-1024x735.png\" alt=\"\" class=\"wp-image-984\" width=\"768\" height=\"551\" srcset=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty1-1024x735.png 1024w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty1-300x215.png 300w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty1-768x551.png 768w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty1.png 1468w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<p class=\"program_discription\">\u5b9f\u969b\u306b\u6a19\u6e96\u5165\u51fa\u529b\u304c\u3069\u3046\u306a\u3063\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<br>\u73fe\u5728\u306e\u30d7\u30ed\u30bb\u30b9ID\u3092\u8abf\u3079\u3066\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u3092\u8868\u793a\u3057\u307e\u3059\u3002<br>\u6a19\u6e96\u5165\u529b0\u3001\u6a19\u6e96\u51fa\u529b1\u3001\u6a19\u6e96\u30a8\u30e9\u30fc2\u304ctty\u30b3\u30de\u30f3\u30c9\u3067\u8868\u793a\u3055\u308c\u308b\u30c7\u30d0\u30a4\u30b9\u306b<br>\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty2-1024x735.png\" alt=\"\" class=\"wp-image-985\" width=\"768\" height=\"551\" srcset=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty2-1024x735.png 1024w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty2-300x215.png 300w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty2-768x551.png 768w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/06\/tty2.png 1468w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<p class=\"program_discription\">\u6a19\u6e96\u5165\u529b\u304ctty\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u305f\u306e\u3067tty\u306e\u5c5e\u6027\u3092\u5909\u66f4\u3057\u3066<br>kbhit\u3068\u540c\u69d8\u306e\u95a2\u6570\u3092<a href=\"https:\/\/www.oji-koji.com\/pro-files\/CommonLinux.zip\">stdThread.cpp, stdThread.h<\/a>\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002<br>\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u672c\u8cea\u3068\u306f\u95a2\u4fc2\u306a\u3044\u306e\u3067\u89e3\u8aac\u306f\u306a\u3057\u3067\u3059\u3002<br>\u6b8b\u5ff5\u306a\u304c\u3089<strong>\u30ea\u30e2\u30fc\u30c8\u30c7\u30d0\u30c3\u30b0\u306e\u74b0\u5883\u3067\u306f\u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\u304ctty\u3067\u306f\u3042\u308a\u307e\u305b\u3093<\/strong>\u306e\u3067<br>\u3053\u308c\u306f\u4f7f\u3048\u307e\u305b\u3093\u3002<strong>\u3053\u308c\u307e\u3067\u901a\u308aselect\u3092\u4f7f\u3063\u305f\u30ad\u30fc\u5165\u529b\u691c\u67fb\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n<p class=\"source_code\">\u3010SimpleClient.cpp\u3011\n#if 1\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b(\u6539\u884c\u307e\u3067)\u306e\u53d6\u5f97\n\/\/        \u5165\u529b\u304c\u306a\u3044\u3068\u304d\u306f\u3059\u3050\u306b\u30ea\u30bf\u30fc\u30f3\n\/\/ parameter\n\/\/    LPSTR      pszString    [in\/out]\u30c7\u30fc\u30bf\u683c\u7d0d\u7528\u30d0\u30c3\u30d5\u30a1\n\/\/    int        iSize        [in]\u30d0\u30c3\u30d5\u30a1\u306e\u30b5\u30a4\u30ba\n\/\/ return\n\/\/    0:\u5165\u529b\u306a\u3057 CMD_QUIT_CHAR:\u7d42\u4e86 CMD_SEND_MSG_CHAR:\u30e1\u30c3\u30bb\u30fc\u30b8\u9001\u4fe1\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nint GetKeyString(LPSTR pszString, int iSize)\n{\n    BOOL            fRet = FALSE;\n    int                iRet = 0;\n\n    if (kbhit())\n    {\n        switch (getchar())\n        {\n            case CMD_QUIT_CHAR:\n                iRet = CMD_QUIT_CHAR;\n                break;\n            case CMD_SEND_MSG_CHAR:\n                fprintf(stderr, &#8220;\\nInput Msg : &#8220;);\n                fgets(pszString, iSize, stdin);\n                if (strlen(pszString) &gt; 0)\n                {\n                \/\/ \u6539\u884c\u307e\u3067\u8aad\u307f\u8fbc\u3093\u3067\u3044\u308b\u306e\u3067\n                    if (pszString[strlen(pszString) &#8211; 1] == &#8216;\\n&#8217;)\n                        pszString[strlen(pszString) &#8211; 1] = 0;\n                    iRet = CMD_SEND_MSG_CHAR;\n                }\n                break;\n            default:\n                break;\n        }\n    }\n    return(iRet);\n}\n#else\n\/\/ \u30ea\u30e2\u30fc\u30c8\u30c7\u30d0\u30c3\u30b0\u3067\u306ftty\u3058\u3083\u306a\u3044\u306e\u3067kbhit\u306f\u4f7f\u3048\u306a\u3044\nint GetKeyString(LPSTR pszString, int iSize)\n{\n    BOOL            fRet = FALSE;\n    int                iRet = 0;\n    fd_set            rfds;\n    struct timeval    tv;\n\n    tv.tv_sec = 0;\n    tv.tv_usec = 1000 * 100;    \/\/ \u5165\u529b\u304c\u306a\u3051\u308c\u307010mec\u306eSleep\n    FD_ZERO(&amp;rfds);             \/\/ fd_set\u306e\u521d\u671f\u5316\n                                \/\/ 0:\u6a19\u6e96\u5165\u529b 1:\u6a19\u6e96\u51fa\u529b 2:\u6a19\u6e96\u30a8\u30e9\u30fc\n    FD_SET(0, &amp;rfds);           \/\/ \u6a19\u6e96\u5165\u529b\u304c\u8abf\u67fb\u5bfe\u8c61\n    select(1, &amp;rfds, NULL, NULL, &amp;tv);\n    if (FD_ISSET(0, &amp;rfds))     \/\/ ENTER\u30ad\u30fc\u5165\u529b\u304c\u3042\u3063\u305f\n    {\n        memset(pszString, 0, iSize);\n        read(0, pszString, iSize);\n        switch (pszString[0])\n        {\n            case CMD_QUIT_CHAR:\n                iRet = CMD_QUIT_CHAR;\n                break;\n            case CMD_SEND_MSG_CHAR:\n                fprintf(stderr, &#8220;\\n\u9001\u4fe1\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 : &#8220;);\n                memset(pszString, 0, iSize);\n                read(0, pszString, iSize);    \/\/ ENTER\u30ad\u30fc\u307e\u3067\u8aad\u307f\u8fbc\u3080\n                if (strlen(pszString) &gt; 0)\n                {\n                    \/\/ \u6539\u884c\u307e\u3067\u8aad\u307f\u8fbc\u3093\u3067\u3044\u308b\u306e\u3067\n                    if (pszString[strlen(pszString) &#8211; 1] == &#8216;\\n&#8217;)\n                        pszString[strlen(pszString) &#8211; 1] = 0;\n                    iRet = CMD_SEND_MSG_CHAR;\n                }\n                break;\n            default:\n                break;\n        }\n    }\n    return(iRet);\n}\n#endif<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SimpleClient\u306e\u30e1\u30cb\u30e5\u30fc\u3067Windows\u306fENTER\u30ad\u30fc\u306a\u3057(1\u6587\u5b57\u5165\u529b\u691c\u51fa)\u3067\u52d5\u3044\u3066\u3044\u307e\u3059\u3002Linux\u3067\u3001\u3053\u308c\u3092\u5b9f\u73fe\u3067\u304d\u306a\u3044\u304b\uff1f\u304c\u30c6\u30fc\u30de\u3067\u3059\u3002\u5b9f\u306f\u3001tty(teletypewriter)\u306e\u5c5e\u6027\u3092\u89e6\u308c\u3070\u3067\u304d\u307e\u3059 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":129,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/www.oji-koji.com\/?p=983","footnotes":""},"categories":[6],"tags":[],"class_list":["post-983","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networkprograming","ja"],"_links":{"self":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=983"}],"version-history":[{"count":3,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/983\/revisions"}],"predecessor-version":[{"id":3093,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/983\/revisions\/3093"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/media\/129"}],"wp:attachment":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}