设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 8387|回复: 11
打印 上一主题 下一主题

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
4018
在线时间
594 小时
注册时间
2014-1-12
帖子
476
跳转到指定楼层
1
发表于 2016-1-15 20:11:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

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

感谢各位水友前来讨论,在@汪汪  
任性的什么也不写

Lv1.梦旅人

梦石
0
星屑
60
在线时间
306 小时
注册时间
2014-8-5
帖子
416
2
发表于 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
  点我进入    
       ↓      
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
帖子
1516
3
发表于 2016-1-15 20:20:27 | 只看该作者
请直接看 input 和 touchinput
可以参考本人 机翻注释mv
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
4018
在线时间
594 小时
注册时间
2014-1-12
帖子
476
4
 楼主| 发表于 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
任性的什么也不写
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
65
在线时间
385 小时
注册时间
2007-7-27
帖子
4106

开拓者

5
发表于 2016-1-15 23:37:49 | 只看该作者
讲道理的话
都是用js的事件回调做的
http://www.dcloud.io/docs/api/zh_cn/key.html
吸吸
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
4018
在线时间
594 小时
注册时间
2014-1-12
帖子
476
6
 楼主| 发表于 2016-1-16 11:18:39 | 只看该作者
本帖最后由 沧笙 于 2016-1-16 11:20 编辑

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

JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // HOY MV Plugins
  3. // HOY_LeaderChange.js
  4. //=============================================================================
  5. /*:
  6.  * @plugindesc 改变队伍带队
  7.  * @author HOY
  8.  *
  9.  * @param keyCode
  10.  * @desc 输入相应的键值
  11.  * @default 72
  12.  *
  13.  * @help
  14.  * ============================================================================
  15.  * 感谢
  16.  * ============================================================================
  17.  * 参考了【夏末渐离】的帖子,源文件改动与其发布的带队插件
  18.  * 详细的键值贴 [url]http://www.cnblogs.com/hsapphire/archive/2009/12/16/1625642.html[/url]
  19.  *
  20.  */
  21.  
  22. $.Param.keyCode = Number($.Parameters.keyCode || 72);
  23.  
  24. Game_Party.prototype.LeadMember=function()
  25. {
  26.         var First_Member =$gameParty._actors.shift();
  27.         $gameParty._actors.push(First_Member);
  28.         $gamePlayer.refresh();
  29. };
  30.  
  31.  
  32. Scene_Map.prototype.update=function()
  33. {
  34.  
  35.         $gameParty.LeadMember();
  36.  
  37. };
  38.  
  39.  
  40. Input._onKeyUp = function(event) {
  41.         if (event.keyCode == $.Param.keyCode) {
  42.                 $Scene_Map.update();
  43.         }
  44. };
  45.  
  46. document.addEventListener('keyup', $Input._onKeyUp());
  47.  
  48. Input.keyMapper = {
  49.  
  50.     72: 'H'     // H
  51. };

点评

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

使用道具 举报

Lv3.寻梦者 (版主)

…あたしは天使なんかじゃないわ

梦石
0
星屑
2208
在线时间
4033 小时
注册时间
2010-10-4
帖子
10779

开拓者贵宾

7
发表于 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
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
帖子
1516
8
发表于 2016-1-17 20:53:26 | 只看该作者
JAVASCRIPT 代码复制
  1. //我觉得...在这里改是最好的,
  2. SceneManager.onKeyDown = function(event) {
  3.     if (!event.ctrlKey && !event.altKey) {
  4.         switch (event.keyCode) {
  5.         case 116:   // F5
  6.             if (Utils.isNwjs()) {
  7.                 location.reload();
  8.             }
  9.             break;
  10.         case 119:   // F8
  11.             if (Utils.isNwjs() && Utils.isOptionValid('test')) {
  12.                 require('nw.gui').Window.get().showDevTools();
  13.             }
  14.             break;
  15.         }
  16.     }
  17. };
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
637
在线时间
164 小时
注册时间
2012-4-18
帖子
264
9
发表于 2016-3-27 10:56:07 | 只看该作者
本帖最后由 salvareless 于 2016-3-27 10:58 编辑

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

使用道具 举报

Lv2.观梦者

梦石
0
星屑
637
在线时间
164 小时
注册时间
2012-4-18
帖子
264
10
发表于 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行。
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-7 11:56

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表