在练字打字的过程之中,一直很好奇,这个打字速度到底可以有多快,目前我的英文的打字水平,估计也就是240字母/分钟。写出来这个打字程序也用于消遣使用,实现了自动打字的基本框架了。

(图一:金山打字通英文打字速度的测试界面)

首先我们要思考一个问题,就是如何才能让程序自动打字?

在我们打字的过程之中,是敲击键盘实现打字的,那么就需要让程序自动的模拟按键,是实现打字的过程。还有一点要考虑的过程就是,如何让计算机知道自己应该模拟的是那些文章。遇到每一个字符是如何处理,遇到特殊的符号,怎么办还有大小写问题。

对于模拟按键问题,这一块在几个月我写过一篇关于模拟按键的问题,已经说的很详细了。

C/C++ 模拟键盘操作(一) https://blog.csdn.net/qq_40757240/article/details/105504524

C/C++ 模拟键盘操作(二)GetKeyState函数详细解释 https://blog.csdn.net/qq_40757240/article/details/105524622

C/C++ 模拟键盘操作(三)模拟鼠标输入 https://blog.csdn.net/qq_40757240/article/details/105543565

C/C++取指示灯状态    https://blog.csdn.net/qq_40757240/article/details/106313373

现在我将设计展示给大家:

实现代码如下:

Key.h

#ifndef KEY_H
#define KEY_H#include <windows.h>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;#define A VK_A
#define a VK_A
#define B VK_B
#define b VK_B
#define C VK_C
#define c VK_C
#define D VK_D
#define d VK_D
#define E 69
#define e 69
#define F VK_F
#define f VK_F
#define G VK_G
#define g VK_G
#define H 72
#define h 72
#define I VK_I
#define i VK_I
#define J VK_J
#define j VK_J
#define K VK_K
#define k VK_K
#define L VK_L
#define l VK_L
#define M VK_M
#define m VK_M
#define N VK_N
#define n VK_N
#define O VK_O
#define o VK_O
#define P VK_P
#define p VK_P
#define Q VK_Q
#define q VK_Q
#define R VK_R
#define r VK_R
#define S VK_S
#define s VK_S
#define T VK_T
#define t VK_T
#define U VK_U
#define u VK_U
#define V VK_V
#define v VK_V
#define W VK_W
#define w VK_W
#define X VK_X
#define x VK_X
#define Y VK_Y
#define y VK_Y
#define Z VK_Z
#define z VK_Z
#define _0 VK_NUMPAD0
#define _1 VK_NUMPAD1
#define _2 VK_NUMPAD2
#define _3 VK_NUMPAD3
#define _4 VK_NUMPAD4
#define _5 VK_NUMPAD5
#define _6 VK_NUMPAD6
#define _7 VK_NUMPAD7
#define _8 VK_NUMPAD8
#define _9 VK_NUMPAD9
#define _ VK_SPACE //空格 //#define ; 186
//#define Caps_Lock 20
class Key
{public:Key();~Key();Key& down(int vk_code);Key& up(int vk_code);Key& press(int vk_code);Key& combination(int vk_code);Key& combination(int vk_code_1,int vk_code_2);Key& combination(int vk_code_1,int vk_code_2,int vk_code_3);Key& combination(int vk_code_1,int vk_code_2,int vk_code_3,int vk_code_4);Key& sleep(int _time);Key& caps(); Key& Caps();Key& setSleepTime(int _time);Key& bearStr(string str);Key& period();Key& comma();int  getTime();private:int time;};#endif

Key.cpp

#include "Key.h"
#include <string>
Key::Key()
{this->time=0; //默认没有延迟 cout<<this->time;
}Key::~Key()
{}
void state()
{/*// 判断键盘CapsLock键是否开启状态,开启状态则为大写,否则为小写if (GetKeyState(VK_CAPITAL)){// 如果当前键盘状态为大写,要求改小写,则模拟按键CapsLock切换状态if (!big){keybd_event(VK_CAPITAL, NULL, KEYEVENTF_EXTENDEDKEY | 0, NULL);keybd_event(VK_CAPITAL, NULL, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, NULL);}}else{// 如果当前键盘状态为小写,要求改大写,则模拟按键CapsLock切换状态He if (big){keybd_event(VK_CAPITAL, NULL, KEYEVENTF_EXTENDEDKEY | 0, NULL);keybd_event(VK_CAPITAL, NULL, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, NULL);}}*///if(!GetKeyStaye(VK_CAPITAL))// {//press(VK_CAPITAL); // }//如果是小写改成大写
}Key& Key::down(int vk_code)
{keybd_event(vk_code,0,0,0);return *this;}
Key& Key::up(int vk_code)
{keybd_event(vk_code,0,KEYEVENTF_KEYUP,0);return *this;}
Key& Key::press(int vk_code)
{if(this->time){this->sleep(this->time);}if(islower(vk_code))//小写字母 {vk_code-=32; }down(vk_code);up(vk_code);return *this;
}
Key& Key::combination(int vk_code)
{press(vk_code);return *this;
}
Key& Key::combination(int vk_code_1,int vk_code_2)
{down(vk_code_1);press(vk_code_2);up(vk_code_1);return *this;
}
Key& Key::combination(int vk_code_1,int vk_code_2,int vk_code_3)
{down(vk_code_1);down(vk_code_2);press(vk_code_3);up(vk_code_2);up(vk_code_1);return *this;
}
Key& Key::combination(int vk_code_1,int vk_code_2,int vk_code_3,int vk_code_4)
{down(vk_code_1);down(vk_code_2);down(vk_code_3);press(vk_code_4);up(vk_code_3);up(vk_code_2);up(vk_code_1);return *this;
}
Key& Key::sleep(int _time)
{Sleep(_time);return *this;
}
Key& Key::caps()
{if (GetKeyState(VK_CAPITAL)){// 如果当前键盘状态为大写,要求改小写,则模拟按键CapsLock切换状态keybd_event(VK_CAPITAL, 0, 0, 0);keybd_event(VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0);}return *this;
}
Key& Key::Caps()
{if (!GetKeyState(VK_CAPITAL)){// 如果当前键盘状态为小写,要求改大写,则模拟按键CapsLock切换状态keybd_event(VK_CAPITAL, 0, 0, 0);keybd_event(VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0);}return *this;
}
Key& Key::setSleepTime(int _time)
{this->time=_time;return *this;
}
Key& Key::period()
{keybd_event(VK_DECIMAL, 0, 0, 0);keybd_event(VK_DECIMAL, 0, KEYEVENTF_KEYUP, 0);return *this;
}
Key& Key::comma()
{keybd_event(188, 0, 0, 0);keybd_event(188, 0, KEYEVENTF_KEYUP, 0);return *this;
}
int Key::getTime()
{return this->time;
}
Key& Key::bearStr(string str)
{for(int cout=0;cout<str.length();cout++){if(isupper(str[cout]))//如果是大写字母{this->Caps();press(str[cout]);this->caps(); }else if(str[cout]=='.'){period();}else if(str[cout]==','){comma();}else{press(str[cout]);}}return *this;
}

main.cpp

#include "Key.h"
#include <string>
#include <iostream>
#include <fstream>
#include <Windows.h>
using namespace std;void fileTest()
{string str;ifstream txt("test.txt");getline(txt,str); //cout<<str;Key *nkey= new Key;nkey->sleep(3000);//nkey->setSleepTime(100);nkey->bearStr(str);
}int main(int argc,char *argv[])
{fileTest();return 0;
}

观看打字效果:

编译运行之后直接将光标放置在打字的软件上输入框就可以了。

备注:

这个软件我已经放置了在了gittee上面 https://gitee.com/shixiongyan/KingsoftTypingTools

测试文件的内容是:

test.txt

He became interested in two theories that possibly explained how cholera killed people. The first suggested that cholera multiplied in the air. A cloud of dangerous gas floated around until it found its victims. The second suggested that people absorbed this disease into their bodies with their meals. From the stomach the disease quickly attacked the body and soon the affected person died. John Snow suspected that the second theory was correct but he needed evidence. So when another outbreak hit London in 1854, he was ready to begin his enquiry. As the disease spread quickly through poor neighbourhoods, he began to gather information. In two particular streets, the cholera outbreak was so severe that more than 500 people died in ten days. He was determined to find out why.

C++实现金山打字通助手相关推荐

  1. 解决金山打字通不能缩小窗口问题

    前段时间,在学五笔, 用的是金山打字通, 但是金山打字通只能全屏显示,这个本没有什么的, 但是我又想在练习的同时看电影,所以这样缩小窗口就显得很重要了 在网上搜索了一下发现金山打字通本身就不能全屏. ...

  2. 小白练打字:金山打字通

    对于小白来说,首先肯定练打字,那么打字软件就很必要了,比如金山打字通 打开界面是这样 如果是完全小白,先用新手入门熟悉键盘 稍有基础则选英文打字进一步熟悉 最后当然练中文 除此之外还有打字 这就是打字 ...

  3. 金山打字通语句练习的文本

    金山打字通语句练习的文本 the with more could seem leave follow fact war company nothing near love often car diff ...

  4. C语言编一个金山打字通小游戏,js实现金山打字通小游戏

    本文实例为大家分享了js实现金山打字通小游戏的具体代码,供大家参考,具体内容如下 字母匀速随机下落,键盘按下对应字母按键,字母消失重新生成新字母,新字母可帮助回调一部分初始高度 效果 1.页面内容 列 ...

  5. 金山打字通生死时速游戏介绍

    金山打字通是一款帮助用户从零开始学习打字的软件,其内置的游戏使打字这一枯燥的活动变得更加有趣.在内置的五款游戏中,属生死时速(又名警察抓小偷)的制作最为精良,可玩性也最高. 设计元素 玩家 角色与特征 ...

  6. Dev-C++游戏创作之金山打字通(附带音乐)

    Hi!大家好!我是你们的编程小王子 最近一直拖着没更新,因为实在是没什么游戏思路.但是终于搞出来一个 金山打字通相信很多小伙伴们都认识,所以东西我就不多介绍,今天主要讲解音乐的播放(超级简单的)! / ...

  7. 金山打字通2011+免升级

    1,金山打字通2011下载地址:http://pan.baidu.com/s/1pKKLxrl ~everything和editplus在百度一搜就可以下载. 2,工具:everything + 金山 ...

  8. 金山打字通屡遭假冒 金山怒批“李鬼”带毒坑用户

    假冒软件不仅危害了正版软件的权益,还会给使用者带来危害,广受欢迎的金山明星产品金山打字通近期又出现了"李鬼"产品,除了假冒软件常有的不稳定.报错.重启 等问题外,假冒软件还携带电脑 ...

  9. 普通域账户不能运行金山打字通的解决方案

    普通域账户不能运行金山打字通 发现用本地管理员账户和域管理员账户能运行 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-c ...

  10. 官方金山打字通2009

    官方金山打字通2009 软件类别:国产软件/教育教学 运行环境: Win98/2000/XP/2003/Vista 软件语言:简体中文 开发作者: 金山软件公司 官方网站:http://www.syy ...

最新文章

  1. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
  2. Google是如何做Code Review的?| CSDN原力计划
  3. keras 实战系列之Self-Attention详细解析
  4. 学习笔记——matplotlib学习
  5. 邮件报文格式和MIME
  6. python安装的模块在pycharm中能用吗_pycharm安装python模块
  7. 领域驱动设计DDD之读书笔记
  8. 创建Windows Mobile上兼容性好的UI 程序
  9. H3C WA2220E-AG 设置本地MAC+PSK认证:mac-and-psk
  10. Python制作2048小游戏
  11. 从零开始配置vim(22)——lsp简介与treesitter 配置
  12. 无需插件只使用浏览器下载b站视频
  13. 支持VS2017的vax插件VA_X_Setup2210
  14. 天气预报接口使用及示例
  15. 金融危机对中国IT产业四大深层影响
  16. 三分钟快速了解怎么查询ip地址,怎么更换ip地址!
  17. 1224. 简单迷宫问题
  18. DataX踩坑2 | 定时任务crontab不执行或报错:/bin/sh: java: command not found
  19. 【历史上的今天】9 月 27 日:“3Q 大战”正式打响;第一个被通缉的电脑黑客;知名“美女病毒”作者被定罪
  20. 春节购机如何选?老司机会告诉你买华为Mate 20 Pro

热门文章

  1. base16、base32和base64转码原理
  2. 【转】Steam 开发者收入计算
  3. minic 动作句型处理
  4. Python实现Mean Shift算法
  5. 语音信号处理——线性预测编码LPC
  6. 计算机网络网线制作工具有,网线制作工具 网线水晶头制作过程详解(视频+图文教程)...
  7. C语言随机数10到999990,C语言程序设计(高清pdf) 丹尼斯 里奇
  8. Arduino开发板使用TFT LCD液晶显示屏的终极新手入门指南
  9. SQL Server数据库学习(1)
  10. project甘特图导出图片_Project2013教程-常见视图-甘特图