查看: 10071|回复: 11

[交流讨论] 【请教】关于按键捕获的问题

[复制链接]
梦石
0
星屑
4325
在线时间
594 小时
注册时间
2014-1-12
回帖
419
发表于 2016-1-15 20:11:08 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
过来找大触们学习学习
【问题】如何捕获玩家按键
【已知】目前查阅资料,
@夏末渐离 使用的是【Input.isTriggered】
@taroxd  提到过【Input.keyMapper】
@真_真空 用到了【Input.isPress】
后来查到还有【event.keyCode】

请问这些的不同是什么?另外怎样可以用keycode的数字来作为判断值?

【补充问题】可否获取玩家按下和抬起按键的操作

感谢各位水友前来讨论,在@汪汪  
任性的什么也不写
梦石
0
星屑
60
在线时间
306 小时
注册时间
2014-8-5
回帖
403
发表于 2016-1-15 20:15:59 | 显示全部楼层
Input.isTriggered(keyName)  //此为Input的方法。检测按键是否刚被按下。
Input.isPress(keyName)   //此为Input的方法。检测按键是否正被按下。
Input.keyMapper              //此为Input的属性。将虚拟按键转换为按键映射名的散列表。

点评

$.onKeyUp = function(event) { if (event.keyCode == $.Param.keyCode) { if (SceneManager._scene instanceof Scene_Map) { $.saveMapshot(); } } 这段是截图插件里的  发表于 2016-1-15 20:53
  点我进入    
       ↓      
回复

使用道具 举报

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2016-1-15 20:20:27 | 显示全部楼层
请直接看 input 和 touchinput
可以参考本人 机翻注释mv
回复

使用道具 举报

梦石
0
星屑
4325
在线时间
594 小时
注册时间
2014-1-12
回帖
419
 楼主| 发表于 2016-1-15 21:02:09 | 显示全部楼层
汪汪 发表于 2016-1-15 20:20
请直接看 input 和 touchinput
可以参考本人 机翻注释mv

嗯嗯,看到了,是这个样子的,我想要的对照按键,自带的里面没有,所以我要写到插件里
那么如果以按键H为例,我需要在插件里这么写吗

if(Input.isTriggered('H'或者72))
    {
        代码段
    }

Input.keyMapper = {

    72: 'H',       // H
}

点评

72:'H'的话。isTriggered('H')就可以,不用(72),因为检查的是键对应的后面的名称。这是为了实现n个键对应游戏里的同一个键。  发表于 2016-1-15 22:05
任性的什么也不写
回复

使用道具 举报

梦石
0
星屑
80
在线时间
386 小时
注册时间
2007-7-27
回帖
4075

开拓者

发表于 2016-1-15 23:37:49 | 显示全部楼层
讲道理的话
都是用js的事件回调做的
http://www.dcloud.io/docs/api/zh_cn/key.html
吸吸
回复

使用道具 举报

梦石
0
星屑
4325
在线时间
594 小时
注册时间
2014-1-12
回帖
419
 楼主| 发表于 2016-1-16 11:18:39 | 显示全部楼层
本帖最后由 沧笙 于 2016-1-16 11:20 编辑

@trentswd @夏末渐离 @汪汪
请问各位前辈,为何这段无法执行呢,我想实现玩家自定义输入键值,即可切换队伍。原有的Input对应键值太少了
这个是全表http://www.cnblogs.com/hsapphire/archive/2009/12/16/1625642.html

[pre lang="javascript"]//=============================================================================
// HOY MV Plugins
// HOY_LeaderChange.js
//=============================================================================
/*:
* @plugindesc 改变队伍带队
* @author HOY
*
* @param keyCode
* @desc 输入相应的键值
* @default 72
*
* @help
* ============================================================================
* 感谢
* ============================================================================
* 参考了【夏末渐离】的帖子,源文件改动与其发布的带队插件
* 详细的键值贴 http://www.cnblogs.com/hsapphire/archive/2009/12/16/1625642.html
*
*/

$.Param.keyCode = Number($.Parameters.keyCode || 72);

Game_Party.prototype.LeadMember=function()
{
        var First_Member =$gameParty._actors.shift();
        $gameParty._actors.push(First_Member);
        $gamePlayer.refresh();
};


Scene_Map.prototype.update=function()
{
       
        $gameParty.LeadMember();
       
};


Input._onKeyUp = function(event) {
        if (event.keyCode == $.Param.keyCode) {
                $Scene_Map.update();
        }
};

document.addEventListener('keyup', $Input._onKeyUp());

Input.keyMapper = {

    72: 'H'     // H
};[/pre]

点评

我需要怎么调用嘞  发表于 2016-1-16 13:07
document.addEventListener('keyup', $Input._onKeyUp())话说这句应该不用添加或者…… 定义一个$Input._onKeyUp() (建议f8打开控制台看一下报错)  发表于 2016-1-16 13:00
你把方法都重写了却没有调用原方法,所以原方法无法运行……  发表于 2016-1-16 12:55
任性的什么也不写
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2016-1-16 16:04:20 | 显示全部楼层
本帖最后由 taroxd 于 2016-1-16 16:07 编辑

要传入 keyCode 的话可以试试这个?
http://taroxd.github.io/rpgmv-plugins/InputExtra.html

点评

这是全键盘操作的插件啊= =  发表于 2016-3-27 11:00
木有看懂  发表于 2016-1-16 19:14
回复

使用道具 举报

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2016-1-17 20:53:26 | 显示全部楼层
[pre lang="javascript"]       
//我觉得...在这里改是最好的,
SceneManager.onKeyDown = function(event) {
    if (!event.ctrlKey && !event.altKey) {
        switch (event.keyCode) {
        case 116:   // F5
            if (Utils.isNwjs()) {
                location.reload();
            }
            break;
        case 119:   // F8
            if (Utils.isNwjs() && Utils.isOptionValid('test')) {
                require('nw.gui').Window.get().showDevTools();
            }
            break;
        }
    }
};
[/pre]
回复

使用道具 举报

梦石
0
星屑
647
在线时间
165 小时
注册时间
2012-4-18
回帖
237
发表于 2016-3-27 10:56:07 | 显示全部楼层
本帖最后由 salvareless 于 2016-3-27 10:58 编辑

我去,这帖子谈论的问题非常实用,但是你们说的内容太高端了= =完全看不懂要怎么应用= =
但求大神们能给个完整的脚本,功能为:按M键执行这个代码($gameVariables.value(80) = 100;)就行了T T
回复

使用道具 举报

梦石
0
星屑
647
在线时间
165 小时
注册时间
2012-4-18
回帖
237
发表于 2016-3-27 18:12:05 | 显示全部楼层
我基本上知道怎么弄了,但是有一点小问题,我使用YEP的键盘公共事件改的,但是为什么只能运行公共事件的代码,我怕改成开关操作的时候就报错?
错误如下:
ReferenceError
invalid left-hand side in assingment  
请问这个错误有没有什么办法排除啊。
我把代码删到了120行,如下:
  1. //=============================================================================
  2. // Yanfly Engine Plugins - Button Common Events
  3. // YEP_ButtonCommonEvents.js
  4. //=============================================================================

  5. var Imported = Imported || {};
  6. Imported.YEP_ButtonCommonEvents = true;

  7. var Yanfly = Yanfly || {};
  8. Yanfly.BCE = Yanfly.BCE || {};

  9. //===============================================================================

  10. /*:
  11. * @param Key M
  12. * @desc 定义M键对应的公共事件ID。0为不启用此功能。
  13. * @default 0

  14. */

  15. //================================================================================

  16. //=============================================================================
  17. // Parameter Variables
  18. //=============================================================================

  19. Yanfly.Parameters = PluginManager.parameters('YEP_ButtonCommonEvents');
  20. Yanfly.Param = Yanfly.Param || {};

  21. Yanfly.Param.BCEList = {
  22.           m: Number(Yanfly.Parameters['Key M']),
  23. //          m: Number(4),
  24. };
  25. Yanfly.Param.Variables = String(Yanfly.Parameters['Variables']);

  26. //=============================================================================
  27. // Input Key Mapper
  28. //=============================================================================

  29. if (Yanfly.Param.BCEList['m'] !== 0) Input.keyMapper[77]          = 'm';

  30. //=============================================================================
  31. // Scene_Base
  32. //=============================================================================

  33. Yanfly.BCE.Scene_Base_start = Scene_Base.prototype.start;
  34. Scene_Base.prototype.start = function() {
  35.     Yanfly.BCE.Scene_Base_start.call(this);
  36. //    Input._revertButton('ALL');
  37. };

  38. //=============================================================================
  39. // Scene_Map
  40. //=============================================================================

  41. Yanfly.BCE.Scene_Map_start = Scene_Map.prototype.start;
  42. Scene_Map.prototype.start = function() {
  43.     Yanfly.BCE.Scene_Map_start.call(this);
  44. //    Input._switchButton('ALL');
  45. };

  46. Yanfly.BCE.Scene_Map_updateScene = Scene_Map.prototype.updateScene;
  47. Scene_Map.prototype.updateScene = function() {
  48.     Yanfly.BCE.Scene_Map_updateScene.call(this);
  49.     if (SceneManager.isSceneChanging()) return;
  50.     if ($gameMap.isEventRunning()) return;
  51.     this.updateButtonEvents();
  52. };
  53. //执行代码的映射区
  54. Scene_Map.prototype.updateButtonEvents = function() {
  55.     for (var key in Yanfly.Param.BCEList) {
  56.       var eventId = Yanfly.Param.BCEList[key];
  57.       if (eventId <= 0) continue;
  58.       if (!Input.isRepeated(key)) continue;
  59.           if (eventId == 4){                                 //增加的
  60.                   $gameSwitches.value(10) = true;   //增加的
  61.           }                                                        //增加的
  62. //      $gameTemp.reserveCommonEvent(eventId);    //原句
  63.       break;
  64.     }
  65. };

  66. //=============================================================================
  67. // Game_Interpreter
  68. //=============================================================================

  69. Yanfly.BCE.Game_Interpreter_pluginCommand =
  70.     Game_Interpreter.prototype.pluginCommand;
  71. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  72.   Yanfly.BCE.Game_Interpreter_pluginCommand.call(this, command, args);
  73.   if (command === 'RevertButton') this.revertButton(args);
  74.   if (command === 'SwitchButton') this.switchButton(args);
  75.   if (command === 'TriggerButton') this.triggerButton(args);
  76. };

  77. Game_Interpreter.prototype.revertButton = function(args) {
  78.   if (!args) return;
  79.   var button = args[0].toUpperCase();
  80.   Input._revertButton(button);
  81. };

  82. Game_Interpreter.prototype.switchButton = function(args) {
  83.   if (!args) return;
  84.   var button = args[0].toUpperCase();
  85.   Input._switchButton(button);
  86. };

  87. Game_Interpreter.prototype.triggerButton = function(args) {
  88.   if (!args) return;
  89.   var button = args[0].toLowerCase();
  90.   if (button === 'cancel') button = 'escape';
  91.   if (button === 'dash') button = 'shift';
  92.   Input._latestButton = button;
  93.   Input._pressedTime = 0;
  94. };

  95. //=============================================================================
  96. // End of File
  97. //=============================================================================
复制代码
我修改的地方在75-77行。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部