跳到正文

个人记录

键盘测试

fangyuhan01约 83 分钟
原文

这是 2026年2月23日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月30日
收录
2026年2月23日
更新
2026年10月29日
篇幅
约 83 分钟

版本

  1. v2当前
  2. v1
C++
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>键盘技能技能测试平台</title>
  <!-- 引入Tailwind CSS -->
  <script src="https://cdn.tailwindcss.com"></script>
  <!-- 引入Font Awesome -->
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
  
  <!-- 配置Tailwind自定义颜色和字体 -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#3B82F6',
            secondary: '#10B981',
            danger: '#EF4444',
            neutral: '#64748B',
            dark: '#1E293B',
          },
          fontFamily: {
            sans: ['Inter', 'system-ui', 'sans-serif'],
          },
        },
      }
    }
  </script>
  
  <!-- 自定义工具类 -->
  <style type="text/tailwindcss">
    @layer utilities {
      .content-auto {
        content-visibility: auto;
      }
      .text-shadow {
        text-shadow: 0 2px 4px rgba(0,0,0,0.1);
      }
      .transition-height {
        transition: max-height 0.5s ease-in-out;
      }
      .keyboard-key {
        @apply bg-gray-100 dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded-md px-3 py-2 text-sm font-medium shadow-sm hover:bg-gray-200 dark:hover:bg-gray-700 transition-all duration-200;
      }
    }
  </style>
  
  <style>
    /* 基础动画和全局样式 */
    body {
      scroll-behavior: smooth;
    }
    
    .pulse {
      animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    }
    
    @keyframes pulse {
      0%, 100% {
        opacity: 1;
      }
      50% {
        opacity: 0.7;
      }
    }
    
    .bounce-in {
      animation: bounce-in 0.6s cubic-bezier(0.215, 0.610, 0.355, 1.000);
    }
    
    @keyframes bounce-in {
      0% { transform: scale(0.3); opacity: 0; }
      50% { transform: scale(1.05); }
      70% { transform: scale(0.9); }
      100% { transform: scale(1); opacity: 1; }
    }
    
    /* 打字区域样式 */
    .typing-correct {
      color: #10B981;
    }
    
    .typing-current {
      background-color: rgba(59, 130, 246, 0.2);
      border-bottom: 2px solid #3B82F6;
    }
    
    .typing-error {
      color: #EF4444;
      text-decoration: underline wavy;
    }
    
    /* 进度条动画 */
    @keyframes progress {
      0% { width: 0%; }
    }
    
    .progress-animation {
      animation: progress 1s linear;
    }
    
    /* 快捷键测试相关样式 */
    #shortcut-content {
      min-height: 80px;
      transition: all 0.3s ease;
    }
    
    .shortcut-highlight {
      background-color: rgba(59, 130, 246, 0.2);
      padding: 0 2px;
    }
  </style>
</head>

<body class="bg-gray-50 dark:bg-gray-900 text-gray-800 dark:text-gray-100 min-h-screen flex flex-col">
  <!-- 顶部导航栏 -->
  <header class="bg-white dark:bg-gray-800 shadow-md sticky top-0 z-50 transition-all duration-300">
    <div class="container mx-auto px-4 py-3 flex justify-between items-center">
      <div class="flex items-center space-x-2">
        <i class="fa fa-keyboard-o text-primary text-2xl"></i>
        <h1 class="text-xl font-bold text-primary">键盘技能测试平台</h1>
      </div>
      
      <div id="user-info" class="hidden items-center space-x-3">
        <span id="student-name" class="font-medium"></span>
        <div class="w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center">
          <i class="fa fa-user text-primary"></i>
        </div>
      </div>
    </div>
  </header>

  <!-- 主要内容区域 -->
  <main class="flex-grow container mx-auto px-4 py-8">
    <!-- 欢迎/姓名输入界面 -->
    <section id="welcome-screen" class="max-w-2xl mx-auto text-center bounce-in">
      <div class="mb-8">
        <i class="fa fa-keyboard-o text-6xl text-primary mb-4"></i>
        <h2 class="text-[clamp(1.8rem,5vw,2.5rem)] font-bold text-dark dark:text-white mb-2">键盘技能测试</h2>
        <p class="text-neutral text-lg">测试你的键盘操作能力,包括打字速度、准确率和快捷键使用</p>
      </div>
      
      <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 md:p-8">
        <form id="name-form" class="space-y-4">
          <div>
            <label for="student-name-input" class="block text-left mb-2 font-medium">请输入你的姓名</label>
            <input 
              type="text" 
              id="student-name-input" 
              required
              minlength="2"
              class="w-full px-4 py-3 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900 focus:ring-2 focus:ring-primary focus:border-primary transition-all outline-none"
              placeholder="请输入姓名开始测试"
            >
          </div>
          
          <div class="p-4 bg-blue-50 dark:bg-blue-900/30 rounded-lg text-left">
            <h4 class="font-medium flex items-center mb-2">
              <i class="fa fa-info-circle text-primary mr-2"></i>测试说明
            </h4>
            <ul class="text-sm space-y-1 text-neutral">
              <li>• 测试包括基础打字、大小写切换、标点符号应用和快捷键操作</li>
              <li>• 禁止复制粘贴,否则将被视为作弊</li>
              <li>• 请确保网络连接稳定</li>
            </ul>
          </div>
          
          <button 
            type="submit" 
            class="w-full bg-primary hover:bg-primary/90 text-white font-medium py-3 px-4 rounded-lg transition-all duration-300 transform hover:scale-[1.02] active:scale-[0.98] shadow-md hover:shadow-lg flex items-center justify-center"
          >
            <span>开始测试</span>
            <i class="fa fa-arrow-right ml-2"></i>
          </button>
        </form>
      </div>
    </section>

    <!-- 测试选择界面 -->
    <section id="test-selection" class="hidden max-w-3xl mx-auto">
      <div class="text-center mb-8">
        <h2 class="text-2xl md:text-3xl font-bold mb-2">选择测试类型</h2>
        <p class="text-neutral">请选择你要进行的键盘技能测试</p>
      </div>
      
      <div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
        <!-- 基础打字测试 -->
        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="basic">
          <div class="w-14 h-14 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mb-4">
            <i class="fa fa-font text-primary text-2xl"></i>
          </div>
          <h3 class="text-xl font-semibold mb-2">基础打字</h3>
          <p class="text-neutral text-sm">测试打字速度和准确率,输入指定文本内容</p>
        </div>
        
        <!-- 大小写切换测试 -->
        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="case">
          <div class="w-14 h-14 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mb-4">
            <i class="fa fa-arrow-up text-secondary text-2xl"></i>
          </div>
          <h3 class="text-xl font-semibold mb-2">大小写切换</h3>
          <p class="text-neutral text-sm">测试大小写切换能力,按要求输入大小写字母</p>
        </div>
        
        <!-- 标点符号测试 -->
        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="punctuation">
          <div class="w-14 h-14 bg-amber-100 dark:bg-amber-900/30 rounded-full flex items-center justify-center mb-4">
            <i class="fa fa-pencil text-amber-600 dark:text-amber-400 text-2xl"></i>
          </div>
          <h3 class="text-xl font-semibold mb-2">标点符号</h3>
          <p class="text-neutral text-sm">测试各种标点符号的输入和应用能力</p>
        </div>
        
        <!-- 快捷键测试 -->
        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="shortcut">
          <div class="w-14 h-14 bg-purple-100 dark:bg-purple-900/30 rounded-full flex items-center justify-center mb-4">
            <i class="fa fa-key text-purple-600 dark:text-purple-400 text-2xl"></i>
          </div>
          <h3 class="text-xl font-semibold mb-2">快捷键测试</h3>
          <p class="text-neutral text-sm">基于文本内容测试常用快捷键使用能力</p>
        </div>
      </div>
    </section>

    <!-- 测试进行界面 -->
    <section id="test-screen" class="hidden max-w-3xl mx-auto">
      <!-- 测试头部信息 -->
      <div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-6 gap-4">
        <div>
          <h2 id="test-title" class="text-2xl font-bold"></h2>
          <p id="test-description" class="text-neutral"></p>
        </div>
        
        <div class="flex gap-4 w-full md:w-auto">
          <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-3 flex-1 md:flex-none md:w-32">
            <p class="text-sm text-neutral">速度 (WPM)</p>
            <p id="wpm-counter" class="text-xl font-bold text-primary">0</p>
          </div>
          
          <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-3 flex-1 md:flex-none md:w-32">
            <p class="text-sm text-neutral">准确率</p>
            <p id="accuracy-counter" class="text-xl font-bold text-secondary">0%</p>
          </div>
          
          <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-3 flex-1 md:flex-none md:w-32">
            <p class="text-sm text-neutral">用时</p>
            <p id="timer" class="text-xl font-bold text-dark dark:text-white">00:00</p>
          </div>
        </div>
      </div>
      
      <!-- 防作弊警告 -->
      <div class="bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-3 mb-6 flex items-start">
        <i class="fa fa-exclamation-triangle text-amber-500 mt-0.5 mr-3"></i>
        <p class="text-sm text-amber-800 dark:text-amber-300">
          <strong>防作弊监测中:</strong>禁止复制粘贴,系统将自动检测作弊行为并记录。
        </p>
      </div>
      
      <!-- 测试内容区域 -->
      <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 mb-6">
        <!-- 基础打字、大小写和标点符号测试内容 -->
        <div id="text-test-container" class="hidden">
          <div id="text-to-type" class="text-lg md:text-xl leading-relaxed mb-6 p-4 bg-gray-50 dark:bg-gray-900 rounded-lg min-h-[120px]">
            <!-- 动态生成的测试文本 -->
          </div>
          
          <div>
            <label for="user-input" class="block text-sm font-medium mb-2">请在此输入</label>
            <textarea 
              id="user-input" 
              class="w-full p-4 border border-gray-300 dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-900 focus:ring-2 focus:ring-primary focus:border-primary transition-all outline-none min-h-[100px] resize-none"
              placeholder="开始输入..."
              autocomplete="off"
              autocorrect="off"
              autocapitalize="off"
              spellcheck="false"
            ></textarea>
          </div>
        </div>
        
        <!-- 快捷键测试内容 -->
        <div id="shortcut-test-container" class="hidden">
          <div class="mb-6">
            <p class="text-sm font-medium mb-2">操作文本:</p>
            <div id="shortcut-content" class="p-4 bg-gray-50 dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700">
              键盘快捷键是提高电脑操作效率的重要技巧,熟练掌握能大幅提升工作学习速度。
            </div>
          </div>
          
          <div id="shortcut-instruction" class="text-lg md:text-xl text-center p-6 bg-gray-50 dark:bg-gray-900 rounded-lg mb-8">
            <!-- 动态生成的快捷键指令 -->
          </div>
          
          <div class="text-center">
            <div id="shortcut-status" class="mb-6 py-4 rounded-lg border-2 border-gray-200 dark:border-gray-700">
              <p class="text-neutral">请按提示的快捷键</p>
            </div>
            
            <div class="flex flex-wrap justify-center gap-3 mb-4">
              <span class="keyboard-key">Ctrl</span>
              <span class="keyboard-key">Shift</span>
              <span class="keyboard-key">Alt</span>
              <span class="keyboard-key">A</span>
              <span class="keyboard-key">C</span>
              <span class="keyboard-key">V</span>
              <span class="keyboard-key">X</span>
              <span class="keyboard-key">Z</span>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 进度条 -->
      <div class="mb-6">
        <div class="flex justify-between text-sm mb-1">
          <span>测试进度</span>
          <span id="progress-percentage">0%</span>
        </div>
        <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2.5">
          <div id="progress-bar" class="bg-primary h-2.5 rounded-full progress-animation" style="width: 0%"></div>
        </div>
      </div>
      
      <!-- 按钮区域 -->
      <div class="flex justify-between">
        <button id="back-to-selection" class="px-5 py-2.5 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 rounded-lg transition-all duration-200">
          <i class="fa fa-arrow-left mr-2"></i>返回选择
        </button>
        
        <button id="submit-test" class="px-5 py-2.5 bg-primary hover:bg-primary/90 text-white rounded-lg transition-all duration-200 hidden">
          提交测试
          <i class="fa fa-check ml-2"></i>
        </button>
      </div>
    </section>

    <!-- 测试结果界面 -->
    <section id="results-screen" class="hidden max-w-2xl mx-auto text-center">
      <div class="mb-8">
        <div class="inline-flex items-center justify-center w-20 h-20 rounded-full bg-green-100 dark:bg-green-900/30 mb-4">
          <i class="fa fa-check text-secondary text-3xl"></i>
        </div>
        <h2 class="text-2xl md:text-3xl font-bold mb-2">测试完成!</h2>
        <p class="text-neutral">以下是你的测试结果</p>
      </div>
      
      <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 md:p-8 mb-6">
        <div class="flex flex-col md:flex-row justify-center gap-8 mb-8">
          <div>
            <p class="text-neutral mb-1">测试类型</p>
            <p id="result-test-type" class="text-xl font-bold"></p>
          </div>
          
          <div>
            <p class="text-neutral mb-1">用时</p>
            <p id="result-time" class="text-xl font-bold"></p>
          </div>
          
          <div>
            <p class="text-neutral mb-1">速度</p>
            <p id="result-wpm" class="text-xl font-bold text-primary"></p>
          </div>
          
          <div>
            <p class="text-neutral mb-1">准确率</p>
            <p id="result-accuracy" class="text-xl font-bold text-secondary"></p>
          </div>
        </div>
        
        <div class="border-t border-gray-200 dark:border-gray-700 pt-6">
          <h3 class="text-lg font-semibold mb-4">详细分析</h3>
          <div id="detailed-analysis" class="text-left space-y-3">
            <!-- 动态生成的详细分析 -->
          </div>
        </div>
      </div>
      
      <div class="flex flex-col sm:flex-row gap-4 justify-center">
        <button id="new-test" class="px-6 py-3 bg-primary hover:bg-primary/90 text-white font-medium rounded-lg transition-all duration-300">
          进行新测试
        </button>
        
        <button id="view-summary" class="px-6 py-3 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 font-medium rounded-lg transition-all duration-300">
          查看总览
        </button>
      </div>
    </section>

    <!-- 总览界面 -->
    <section id="summary-screen" class="hidden max-w-3xl mx-auto">
      <div class="text-center mb-8">
        <h2 class="text-2xl md:text-3xl font-bold mb-2">测试总览</h2>
        <p class="text-neutral">你的所有测试记录和表现分析</p>
      </div>
      
      <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 mb-6">
        <div class="grid md:grid-cols-3 gap-6 mb-8">
          <div class="p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg">
            <p class="text-neutral text-sm mb-1">已完成测试</p>
            <p id="total-tests" class="text-3xl font-bold text-primary">0</p>
          </div>
          
          <div class="p-4 bg-green-50 dark:bg-green-900/20 rounded-lg">
            <p class="text-neutral text-sm mb-1">平均准确率</p>
            <p id="avg-accuracy" class="text-3xl font-bold text-secondary">0%</p>
          </div>
          
          <div class="p-4 bg-purple-50 dark:bg-purple-900/20 rounded-lg">
            <p class="text-neutral text-sm mb-1">平均速度</p>
            <p id="avg-wpm" class="text-3xl font-bold text-purple-600 dark:text-purple-400">0 WPM</p>
          </div>
        </div>
        
        <h3 class="text-lg font-semibold mb-4">测试历史</h3>
        <div class="overflow-x-auto">
          <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
            <thead>
              <tr>
                <th class="px-4 py-3 bg-gray-50 dark:bg-gray-900 text-left text-xs font-medium text-neutral uppercase tracking-wider">测试类型</th>
                <th class="px-4 py-3 bg-gray-50 dark:bg-gray-900 text-left text-xs font-medium text-neutral uppercase tracking-wider">用时</th>
                <th class="px-4 py-3 bg-gray-50 dark:bg-gray-900 text-left text-xs font-medium text-neutral uppercase tracking-wider">速度</th>
                <th class="px-4 py-3 bg-gray-50 dark:bg-gray-900 text-left text-xs font-medium text-neutral uppercase tracking-wider">准确率</th>
                <th class="px-4 py-3 bg-gray-50 dark:bg-gray-900 text-left text-xs font-medium text-neutral uppercase tracking-wider">日期</th>
              </tr>
            </thead>
            <tbody id="test-history" class="divide-y divide-gray-200 dark:divide-gray-700">
              <!-- 动态生成的测试历史 -->
              <tr>
                <td colspan="5" class="px-4 py-8 text-center text-neutral">暂无测试记录</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      
      <div class="text-center">
        <button id="back-to-tests" class="px-6 py-3 bg-primary hover:bg-primary/90 text-white font-medium rounded-lg transition-all duration-300">
          返回测试
        </button>
      </div>
    </section>
  </main>

  <!-- 页脚 -->
  <footer class="bg-white dark:bg-gray-800 shadow-inner py-6">
    <div class="container mx-auto px-4 text-center text-neutral text-sm">
      <p>键盘技能测试平台 &copy; 2023 | 设计用于评估基本键盘操作能力</p>
    </div>
  </footer>

  <!-- 作弊警告模态框 -->
  <div id="cheat-modal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden items-center justify-center">
    <div class="bg-white dark:bg-gray-800 rounded-xl shadow-xl p-6 max-w-md w-full mx-4 bounce-in">
      <div class="text-center mb-4">
        <div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-red-100 dark:bg-red-900/30 mb-4">
          <i class="fa fa-exclamation-circle text-danger text-2xl"></i>
        </div>
        <h3 class="text-xl font-bold text-danger mb-2">检测到作弊行为</h3>
        <p class="text-neutral">复制粘贴操作已被禁止。请使用键盘手动输入完成测试。</p>
      </div>
      
      <div class="text-center">
        <button id="close-cheat-modal" class="px-5 py-2.5 bg-danger hover:bg-danger/90 text-white rounded-lg transition-all duration-200">
          我知道了
        </button>
      </div>
    </div>
  </div>

  <script>
    // 全局变量
    let currentTest = null;
    let studentName = '';
    let testStartTime = 0;
    let timerInterval = null;
    let testData = {
      type: '',
      text: '',
      userInput: '',
      startTime: 0,
      endTime: 0,
      errors: 0,
      totalChars: 0,
      shortcutAttempts: [],
      shortcutSuccess: 0
    };
    let testHistory = JSON.parse(localStorage.getItem('keyboardTestHistory')) || [];
    
    // DOM元素
    const welcomeScreen = document.getElementById('welcome-screen');
    const testSelection = document.getElementById('test-selection');
    const testScreen = document.getElementById('test-screen');
    const resultsScreen = document.getElementById('results-screen');
    const summaryScreen = document.getElementById('summary-screen');
    const nameForm = document.getElementById('name-form');
    const studentNameInput = document.getElementById('student-name-input');
    const studentNameDisplay = document.getElementById('student-name');
    const userInfo = document.getElementById('user-info');
    const testCards = document.querySelectorAll('.test-card');
    const testTitle = document.getElementById('test-title');
    const testDescription = document.getElementById('test-description');
    const textToType = document.getElementById('text-to-type');
    const userInput = document.getElementById('user-input');
    const shortcutInstruction = document.getElementById('shortcut-instruction');
    const shortcutStatus = document.getElementById('shortcut-status');
    const shortcutContent = document.getElementById('shortcut-content');
    const textTestContainer = document.getElementById('text-test-container');
    const shortcutTestContainer = document.getElementById('shortcut-test-container');
    const wpmCounter = document.getElementById('wpm-counter');
    const accuracyCounter = document.getElementById('accuracy-counter');
    const timer = document.getElementById('timer');
    const progressBar = document.getElementById('progress-bar');
    const progressPercentage = document.getElementById('progress-percentage');
    const backToSelection = document.getElementById('back-to-selection');
    const submitTest = document.getElementById('submit-test');
    const newTest = document.getElementById('new-test');
    const viewSummary = document.getElementById('view-summary');
    const backToTests = document.getElementById('back-to-tests');
    const cheatModal = document.getElementById('cheat-modal');
    const closeCheatModal = document.getElementById('close-cheat-modal');
    
    // 测试文本数据
    const testTexts = {
      basic: [
        "计算机键盘是计算机的重要输入设备,熟练掌握键盘操作是提高计算机使用效率的基础。多加练习能进步更快。",
        "打字练习需要耐心和坚持,每天练习15分钟比一周练习一次2小时效果更好。坚持就是胜利。",
        "正确的打字姿势不仅能提高速度,还能减少手腕疲劳和受伤的风险。健康打字很重要。",
        "触摸打字是一种不看键盘的打字方法,通过手指的肌肉记忆来敲击按键。掌握后效率高。",
        "随着练习的深入,你的打字速度和准确率会逐步提高,形成条件反射。加油你能行。"
      ],
      case: [
        "AbCdEfGhIjKlMnOpQrStUvWxYz",
        "aBcDeFgHiJkLmNoPqRsTuVwXyZ",
        "1Aa2Bb3Cc4Dd5Ee6Ff7Gg8Hh9Ii0Jj",
        "键盘输入要注意大小写切换,Caps Lock和Shift键都可以改变字母大小写。"
      ],
      punctuation: [
        "今天天气真好!我们一起去公园玩吧?你觉得怎么样。",
        "他说:“我明天会来的;请你等我一下。”",
        "这是第一点、这是第二点、这是第三点……",
        "北京(中国首都)是一座美丽的城市,有着3000多年的历史。",
        "她买了苹果5个,香蕉10根,橘子15斤,总共花了88元。"
      ]
    };
    
    // 快捷键测试数据
    const shortcutTests = [
      { 
        key: 'a', 
        modifier: 'ctrl', 
        description: '全选文本 (Ctrl + A)',
        action: 'selectAll',
        successMsg: '已成功全选文本!'
      },
      { 
        key: 'c', 
        modifier: 'ctrl', 
        description: '复制选中的文本 (Ctrl + C)',
        action: 'copy',
        successMsg: '已成功复制文本!'
      },
      { 
        key: 'v', 
        modifier: 'ctrl', 
        description: '粘贴复制的文本 (Ctrl + V)',
        action: 'paste',
        successMsg: '已成功粘贴文本!'
      },
      { 
        key: 'x', 
        modifier: 'ctrl', 
        description: '剪切选中的文本 (Ctrl + X)',
        action: 'cut',
        successMsg: '已成功剪切文本!'
      },
      { 
        key: 'z', 
        modifier: 'ctrl', 
        description: '撤销上一步操作 (Ctrl + Z)',
        action: 'undo',
        successMsg: '已成功撤销操作!'
      },
      { 
        key: 'f', 
        modifier: 'ctrl', 
        description: '查找文本内容 (Ctrl + F)',
        action: 'find',
        successMsg: '已成功打开查找功能!'
      },
      { 
        key: 's', 
        modifier: 'ctrl', 
        description: '保存当前内容 (Ctrl + S)',
        action: 'save',
        successMsg: '已成功执行保存操作!'
      }
    ];
    
    // 初始化事件监听
    function initEventListeners() {
      // 姓名表单提交
      nameForm.addEventListener('submit', (e) => {
        e.preventDefault();
        studentName = studentNameInput.value.trim();
        if (studentName) {
          studentNameDisplay.textContent = studentName;
          userInfo.classList.remove('hidden');
          userInfo.classList.add('flex');
          showScreen(testSelection);
        }
      });
      
      // 测试类型选择
      testCards.forEach(card => {
        card.addEventListener('click', () => {
          const testType = card.getAttribute('data-test');
          startTest(testType);
        });
      });
      
      // 返回测试选择
      backToSelection.addEventListener('click', () => {
        endTest();
        showScreen(testSelection);
      });
      
      // 提交测试
      submitTest.addEventListener('click', calculateResults);
      
      // 新测试
      newTest.addEventListener('click', () => {
        showScreen(testSelection);
      });
      
      // 查看总览
      viewSummary.addEventListener('click', showSummary);
      
      // 返回测试
      backToTests.addEventListener('click', () => {
        showScreen(testSelection);
      });
      
      // 关闭作弊警告
      closeCheatModal.addEventListener('click', () => {
        cheatModal.classList.remove('flex');
        cheatModal.classList.add('hidden');
      });
      
      // 防复制粘贴
      document.addEventListener('copy', (e) => {
        if (testScreen.classList.contains('flex')) {
          e.preventDefault();
          showCheatWarning();
        }
      });
      
      document.addEventListener('paste', (e) => {
        if (testScreen.classList.contains('flex')) {
          e.preventDefault();
          showCheatWarning();
        }
      });
      
      // 输入监听
      userInput.addEventListener('input', handleTextInput);
      
      // 快捷键监听
      document.addEventListener('keydown', handleKeyDown);
    }
    
    // 显示指定屏幕
    function showScreen(screen) {
      [welcomeScreen, testSelection, testScreen, resultsScreen, summaryScreen].forEach(s => {
        s.classList.add('hidden');
        s.classList.remove('flex', 'flex-col');
      });
      
      screen.classList.remove('hidden');
      screen.classList.add('flex', 'flex-col');
    }
    
    // 开始测试
    function startTest(testType) {
      currentTest = testType;
      testData = {
        type: testType,
        text: '',
        userInput: '',
        startTime: Date.now(),
        endTime: 0,
        errors: 0,
        totalChars: 0,
        shortcutAttempts: [],
        shortcutSuccess: 0,
        currentShortcutIndex: 0,
        originalContent: '键盘快捷键是提高电脑操作效率的重要技巧,熟练掌握能大幅提升工作学习速度。'
      };
      
      // 设置测试标题和描述
      switch(testType) {
        case 'basic':
          testTitle.textContent = '基础打字测试';
          testDescription.textContent = '请尽可能准确快速地输入下方文本内容';
          setupTextTest('basic');
          break;
        case 'case':
          testTitle.textContent = '大小写切换测试';
          testDescription.textContent = '注意字母大小写,准确输入下方文本内容';
          setupTextTest('case');
          break;
        case 'punctuation':
          testTitle.textContent = '标点符号应用测试';
          testDescription.textContent = '注意各种标点符号,准确输入下方文本内容';
          setupTextTest('punctuation');
          break;
        case 'shortcut':
          testTitle.textContent = '快捷键测试';
          testDescription.textContent = '根据提示对下方文本执行相应的快捷键操作';
          setupShortcutTest();
          break;
      }
      
      // 重置计数器
      wpmCounter.textContent = '0';
      accuracyCounter.textContent = '0%';
      timer.textContent = '00:00';
      progressBar.style.width = '0%';
      progressPercentage.textContent = '0%';
      
      // 开始计时
      startTimer();
      
      // 显示测试屏幕
      showScreen(testScreen);
      
      // 自动聚焦到输入框
      if (testType !== 'shortcut') {
        userInput.focus();
      } else {
        shortcutContent.focus();
      }
    }
    
    // 设置文本测试
    function setupTextTest(type) {
      // 显示文本测试容器,隐藏快捷键容器
      textTestContainer.classList.remove('hidden');
      shortcutTestContainer.classList.add('hidden');
      
      // 随机选择一个测试文本
      const textIndex = Math.floor(Math.random() * testTexts[type].length);
      testData.text = testTexts[type][textIndex];
      testData.totalChars = testData.text.length;
      
      // 渲染测试文本
      renderTestText();
      
      // 清空输入框
      userInput.value = '';
    }
    
    // 渲染测试文本
    function renderTestText() {
      textToType.innerHTML = '';
      
      // 拆分文本为单个字符并添加到DOM
      for (let i = 0; i < testData.text.length; i++) {
        const charSpan = document.createElement('span');
        charSpan.textContent = testData.text[i];
        charSpan.classList.add('inline-block');
        
        // 已输入的字符
        if (i < testData.userInput.length) {
          // 正确或错误的字符
          if (testData.userInput[i] === testData.text[i]) {
            charSpan.classList.add('typing-correct');
          } else {
            charSpan.classList.add('typing-error');
          }
        } 
        // 当前需要输入的字符
        else if (i === testData.userInput.length) {
          charSpan.classList.add('typing-current');
        }
        
        textToType.appendChild(charSpan);
      }
      
      // 更新进度
      updateProgress();
      
      // 检查是否完成
      if (testData.userInput.length === testData.text.length) {
        submitTest.classList.remove('hidden');
      } else {
        submitTest.classList.add('hidden');
      }
    }
    
    // 设置快捷键测试
    function setupShortcutTest() {
      // 显示快捷键测试容器,隐藏文本容器
      textTestContainer.classList.add('hidden');
      shortcutTestContainer.classList.remove('hidden');
      
      // 初始化文本内容
      shortcutContent.textContent = testData.originalContent;
      
      // 打乱快捷键测试顺序
      testData.shortcutTests = [...shortcutTests].sort(() => Math.random() - 0.5);
      testData.currentShortcutIndex = 0;
      
      // 显示第一个快捷键测试
      showCurrentShortcut();
    }
    
    // 显示当前快捷键测试
    function showCurrentShortcut() {
      if (testData.currentShortcutIndex < testData.shortcutTests.length) {
        const current = testData.shortcutTests[testData.currentShortcutIndex];
        shortcutInstruction.textContent = `请执行: ${current.description}`;
        shortcutStatus.innerHTML = `<p class="text-neutral">请按提示的快捷键操作文本</p>`;
      } else {
        // 所有快捷键测试完成
        shortcutInstruction.textContent = '所有快捷键测试已完成!';
        shortcutStatus.innerHTML = `<p class="text-secondary"><i class="fa fa-check-circle mr-1"></i> 全部完成</p>`;
        submitTest.classList.remove('hidden');
      }
    }
    
    // 处理文本输入
    function handleTextInput() {
      const input = userInput.value;
      testData.userInput = input;
      
      // 计算错误数量
      let errors = 0;
      for (let i = 0; i < input.length; i++) {
        if (i >= testData.text.length) {
          errors++;
        } else if (input[i] !== testData.text[i]) {
          errors++;
        }
      }
      testData.errors = errors;
      
      // 更新显示
      renderTestText();
      updateStats();
    }
    
    // 处理按键事件
    function handleKeyDown(e) {
      // 只在快捷键测试中处理
      if (currentTest !== 'shortcut' || testData.currentShortcutIndex >= testData.shortcutTests.length) {
        return;
      }
      
      const current = testData.shortcutTests[testData.currentShortcutIndex];
      const isCtrl = e.ctrlKey;
      const isShift = e.shiftKey;
      const isAlt = e.altKey;
      const key = e.key.toLowerCase();
      
      // 检查是否匹配当前快捷键
      if (current.modifier === 'ctrl' && isCtrl && !isShift && !isAlt && key === current.key) {
        e.preventDefault();
        testData.shortcutSuccess++;
        
        // 根据不同快捷键执行相应的视觉反馈
        switch(current.action) {
          case 'selectAll':
            // 模拟全选效果
            shortcutContent.innerHTML = `<span class="shortcut-highlight">${shortcutContent.textContent}</span>`;
            break;
          case 'cut':
            // 模拟剪切效果
            shortcutContent.textContent = '';
            break;
          case 'paste':
            // 模拟粘贴效果
            if (shortcutContent.textContent === '') {
              shortcutContent.textContent = testData.originalContent;
            } else {
              shortcutContent.textContent += ' ' + testData.originalContent;
            }
            break;
          case 'undo':
            // 模拟撤销效果
            shortcutContent.textContent = testData.originalContent;
            break;
          // 其他操作不需要改变文本,只需要反馈
        }
        
        shortcutStatus.innerHTML = `<p class="text-secondary"><i class="fa fa-check-circle mr-1"></i> ${current.successMsg}</p>`;
        
        // 延迟显示下一个快捷键
        setTimeout(() => {
          testData.currentShortcutIndex++;
          showCurrentShortcut();
          updateProgress();
          updateStats();
        }, 1200);
      } else if (key === current.key && !isCtrl && !isShift && !isAlt) {
        // 只按了字母键,没有按修饰键
        shortcutStatus.innerHTML = `<p class="text-danger"><i class="fa fa-times-circle mr-1"></i> 请同时按下 ${current.modifier.toUpperCase()} 键</p>`;
      }
    }
    
    // 开始计时器
    function startTimer() {
      testStartTime = Date.now();
      
      if (timerInterval) {
        clearInterval(timerInterval);
      }
      
      timerInterval = setInterval(() => {
        const elapsedTime = Math.floor((Date.now() - testStartTime) / 1000);
        const minutes = Math.floor(elapsedTime / 60).toString().padStart(2, '0');
        const seconds = (elapsedTime % 60).toString().padStart(2, '0');
        timer.textContent = `${minutes}:${seconds}`;
        
        // 更新统计数据
        updateStats();
      }, 1000);
    }
    
    // 更新进度
    function updateProgress() {
      let progress = 0;
      
      if (currentTest === 'shortcut') {
        progress = (testData.currentShortcutIndex / testData.shortcutTests.length) * 100;
      } else {
        progress = (testData.userInput.length / testData.text.length) * 100;
      }
      
      progress = Math.min(100, Math.round(progress));
      progressBar.style.width = `${progress}%`;
      progressPercentage.textContent = `${progress}%`;
    }
    
    // 更新统计数据
    function updateStats() {
      const elapsedMinutes = (Date.now() - testStartTime) / (1000 * 60);
      
      if (currentTest === 'shortcut') {
        // 快捷键测试统计
        const accuracy = testData.shortcutTests.length > 0 
          ? Math.round((testData.shortcutSuccess / testData.shortcutTests.length) * 100)
          : 0;
        
        accuracyCounter.textContent = `${accuracy}%`;
        wpmCounter.textContent = 'N/A'; // 快捷键测试不计算WPM
      } else {
        // 文本测试统计
        const typedChars = testData.userInput.length;
        const correctChars = typedChars - testData.errors;
        const accuracy = typedChars > 0 
          ? Math.round((correctChars / typedChars) * 100)
          : 0;
        
        // 计算每分钟字数 (WPM)
        const wpm = elapsedMinutes > 0 
          ? Math.round(typedChars / 5 / elapsedMinutes) // 平均5个字符一个词
          : 0;
        
        accuracyCounter.textContent = `${accuracy}%`;
        wpmCounter.textContent = wpm.toString();
      }
    }
    
    // 计算并显示测试结果
    function calculateResults() {
      endTest();
      
      // 记录结束时间
      testData.endTime = Date.now();
      const elapsedTimeMs = testData.endTime - testData.startTime;
      const elapsedMinutes = elapsedTimeMs / (1000 * 60);
      const elapsedSeconds = Math.floor(elapsedTimeMs / 1000);
      const timeDisplay = `${Math.floor(elapsedSeconds / 60)}分${elapsedSeconds % 60}秒`;
      
      // 计算结果
      let wpm = 0;
      let accuracy = 0;
      let analysis = '';
      
      if (currentTest === 'shortcut') {
        accuracy = Math.round((testData.shortcutSuccess / testData.shortcutTests.length) * 100);
        
        analysis = `
          <p>• 共完成 ${testData.shortcutTests.length} 个快捷键测试</p>
          <p>• 正确操作: ${testData.shortcutSuccess} 个</p>
          <p>• 错误操作: ${testData.shortcutTests.length - testData.shortcutSuccess} 个</p>
        `;
      } else {
        const typedChars = testData.userInput.length;
        const correctChars = typedChars - testData.errors;
        
        accuracy = typedChars > 0 
          ? Math.round((correctChars / typedChars) * 100)
          : 0;
        
        wpm = elapsedMinutes > 0 
          ? Math.round(typedChars / 5 / elapsedMinutes)
          : 0;
        
        // 针对标点符号测试的特殊分析
        if (currentTest === 'punctuation') {
          // 统计标点符号错误
          const punctuationMarks = ['.', ',', ';', ':', '!', '?', '"', "'", '(', ')', '《', '》', '「', '」', ',', '。', ';', ':', '!', '?'];
          let punctuationErrors = 0;
          let totalPunctuation = 0;
          
          for (let i = 0; i < Math.min(testData.text.length, testData.userInput.length); i++) {
            if (punctuationMarks.includes(testData.text[i])) {
              totalPunctuation++;
              if (testData.text[i] !== testData.userInput[i]) {
                punctuationErrors++;
              }
            }
          }
          
          analysis = `
            <p>• 总输入字符: ${typedChars} 个</p>
            <p>• 正确字符: ${correctChars} 个</p>
            <p>• 错误字符: ${testData.errors} 个</p>
            <p>• 标点符号总数: ${totalPunctuation} 个</p>
            <p>• 标点符号错误: ${punctuationErrors} 个</p>
            <p>• 速度评估: ${getSpeedRating(wpm)}</p>
            <p>• 准确率评估: ${getAccuracyRating(accuracy)}</p>
          `;
        } else {
          analysis = `
            <p>• 总输入字符: ${typedChars} 个</p>
            <p>• 正确字符: ${correctChars} 个</p>
            <p>• 错误字符: ${testData.errors} 个</p>
            <p>• 速度评估: ${getSpeedRating(wpm)}</p>
            <p>• 准确率评估: ${getAccuracyRating(accuracy)}</p>
          `;
        }
      }
      
      // 保存测试结果
      const testResult = {
        studentName,
        type: currentTest,
        typeName: getTestTypeName(currentTest),
        time: timeDisplay,
        timeSeconds: elapsedSeconds,
        wpm: currentTest === 'shortcut' ? 'N/A' : wpm,
        accuracy: `${accuracy}%`,
        accuracyValue: accuracy,
        date: new Date().toISOString()
      };
      
      testHistory.push(testResult);
      localStorage.setItem('keyboardTestHistory', JSON.stringify(testHistory));
      
      // 更新结果界面
      document.getElementById('result-test-type').textContent = getTestTypeName(currentTest);
      document.getElementById('result-time').textContent = timeDisplay;
      document.getElementById('result-wpm').textContent = currentTest === 'shortcut' ? 'N/A' : `${wpm} WPM`;
      document.getElementById('result-accuracy').textContent = `${accuracy}%`;
      document.getElementById('detailed-analysis').innerHTML = analysis;
      
      // 显示结果界面
      showScreen(resultsScreen);
    }
    
    // 结束测试
    function endTest() {
      if (timerInterval) {
        clearInterval(timerInterval);
        timerInterval = null;
      }
    }
    
    // 显示作弊警告
    function showCheatWarning() {
      cheatModal.classList.remove('hidden');
      cheatModal.classList.add('flex');
    }
    
    // 显示总览
    function showSummary() {
      // 计算统计数据
      const totalTests = testHistory.length;
      let totalAccuracy = 0;
      let accuracyCount = 0;
      let totalWpm = 0;
      let wpmCount = 0;
      
      testHistory.forEach(test => {
        totalAccuracy += test.accuracyValue;
        accuracyCount++;
        
        if (test.wpm !== 'N/A') {
          totalWpm += test.wpm;
          wpmCount++;
        }
      });
      
      const avgAccuracy = accuracyCount > 0 ? Math.round(totalAccuracy / accuracyCount) : 0;
      const avgWpm = wpmCount > 0 ? Math.round(totalWpm / wpmCount) : 0;
      
      // 更新统计数据显示
      document.getElementById('total-tests').textContent = totalTests;
      document.getElementById('avg-accuracy').textContent = `${avgAccuracy}%`;
      document.getElementById('avg-wpm').textContent = `${avgWpm} WPM`;
      
      // 更新测试历史表格
      const testHistoryEl = document.getElementById('test-history');
      
      if (totalTests === 0) {
        testHistoryEl.innerHTML = `
          <tr>
            <td colspan="5" class="px-4 py-8 text-center text-neutral">暂无测试记录</td>
          </tr>
        `;
      } else {
        // 按日期排序,最新的在前
        const sortedHistory = [...testHistory].sort((a, b) => new Date(b.date) - new Date(a.date));
        
        testHistoryEl.innerHTML = sortedHistory.map(test => `
          <tr>
            <td class="px-4 py-3">${test.typeName}</td>
            <td class="px-4 py-3">${test.time}</td>
            <td class="px-4 py-3">${test.wpm}</td>
            <td class="px-4 py-3">${test.accuracy}</td>
            <td class="px-4 py-3">${formatDate(test.date)}</td>
          </tr>
        `).join('');
      }
      
      // 显示总览界面
      showScreen(summaryScreen);
    }
    
    // 辅助函数:获取测试类型名称
    function getTestTypeName(type) {
      const types = {
        'basic': '基础打字',
        'case': '大小写切换',
        'punctuation': '标点符号应用',
        'shortcut': '快捷键'
      };
      return types[type] || type;
    }
    
    // 辅助函数:格式化日期
    function formatDate(dateString) {
      const date = new Date(dateString);
      return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
    }
    
    // 辅助函数:获取速度评级
    function getSpeedRating(wpm) {
      if (wpm < 10) return '入门级,继续练习';
      if (wpm < 20) return '初级水平,有提升空间';
      if (wpm < 30) return '中等水平,表现不错';
      if (wpm < 40) return '良好水平,继续保持';
      if (wpm < 50) return '优秀水平,非常出色';
      return '专业水平,令人印象深刻';
    }
    
    // 辅助函数:获取准确率评级
    function getAccuracyRating(accuracy) {
      if (accuracy < 70) return '需要提高准确性';
      if (accuracy < 80) return '良好,继续努力';
      if (accuracy < 90) return '优秀,很少出错';
      return '非常精准,几乎没有错误';
    }
    
    // 初始化应用
    function init() {
      initEventListeners();
      showScreen(welcomeScreen);
    }
    
    // 启动应用
    document.addEventListener('DOMContentLoaded', init);
  </script>
</body>
</html>