所以我有一个带有Form的C#控制台应用程序,我想用热键打开它.比如说Ctrl+ <打开表单.所以我现在得到了处理globalkeylistener的代码,但看起来我实现它失败了.它创建了一个while循环来阻止它关闭程序,我尝试使用kbh_OnKeyPressed方法从用户那里获得输入.
我试着用这种方式实现它:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Globalkey
{
static class Program
{
[DllImport("user32.dll")]
private static extern bool RegisterHotkey(int id, uint fsModifiers, uint vk);
private static bool lctrlKeyPressed;
private static bool f1KeyPressed;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();
kbh.OnKeyPressed += kbh_OnKeyPressed;
kbh.OnKeyUnpressed += kbh_OnKeyUnpressed;
kbh.HookKeyboard();
while(true) { }
}
private static void kbh_OnKeyUnpressed(object sender, Keys e)
{
if (e == Keys.LControlKey)
{ …Run Code Online (Sandbox Code Playgroud) 我想制作一个经典的像素RPG.
首先,我从未使用过WPF,所以我真的不知道具体的好处是什么.我的问题很简单.我已经习惯了WinForms,所以我更喜欢使用它创建一个游戏,但我觉得WinForms并不是为游戏开发而制作的.
使用WPF或其他框架/引擎有什么好处吗?