小编Xeo*_*eon的帖子

Linux X11 - 全局键盘钩

是否有可能(或如何)创建一个与Windows中的全局钩子(SetWindowsHookEx())类似的机制(在Linux X11,C++中)?

我希望能够抓住关键事件,但有可能进一步传播.我正在尝试使用XGrabKey解决方案(就像在xbindkeys中一样),但是当我设置捕获键事件时,此事件被"消耗".

该机制的要求如下:

  1. 全局/系统范围 - 无论具有焦点的窗口如何都捕获事件
  2. "抓住"和"抓住通过"的可能性
  3. 它一定很快

示例代码如下所示:

bool myFlagIsSet = false;
XEvent event;
while (true) {
    while (XPending(display) > 0) {
        usleep(SLEEP_TIME);
    }

    XNextEvent(display, &event);
    switch (e.type) {
        case KeyPress:
            if (myFlagIsSet) {
                //do not propagate
            }
            // propagate
            break;
        case KeyRelease:
            if (myFlagIsSet) {
                //do not propagate
            }
            // propagate
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

在Windows上我简单地写道:

if(event.isConsumed()) {
    return LRESULT(1);
}
//...
return CallNextHookEx(hookHandle, nCode, wParam, lParam);
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用XUngrabKey和XSendEvent:

switch (event.type) {
    case …
Run Code Online (Sandbox Code Playgroud)

c++ linux x11 hook

27
推荐指数
2
解决办法
1万
查看次数

Maven 2 - 测试和编译中的不同依赖版本

我的项目依赖于commons-httpclient [2.0](编译).

我想写一些jbehave测试 - jbehave-core 3.4.5(测试).这两个依赖项都依赖于commons-lang,但是在不同的版本中 - 1.0.1和2.5.

依赖

当我执行mvn包时,我在测试部分得到[BUID FAILURE].在surefire-plugin输出中我的测试用例有一个例外:

java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.substringBeforeLast(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
Run Code Online (Sandbox Code Playgroud)

当我查看源代码时 - 在commons-lang 1.0.1中 - 实际上,没有StringUtils.substringBeforeLast(...)方法.为什么maven在commons-httpclient(编译)中使用commons-lang而在测试中不使用jbehave-core?

我不能在commons-httpclient中排除这个冲突的依赖,所以它必须保持编译时间.

那么如何解决这个问题呢? - 测试中的commons-lang 2.5版本和编译时的1.0.1版本.

java maven-2 versions maven

12
推荐指数
1
解决办法
7276
查看次数

在Intent中设置后,Bundle为null

我知道有一些问题,例如: android-intent-bundle-always-nullintent-bundle-returns-null-every-time但是没有正确的答案.

在我的Activity 1:

public void goToMapView(Info info) {
    Intent intent = new Intent(getApplicationContext(), MapViewActivity.class);
    //intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    intent.putExtra("asdf", true);
    info.write(intent);
    startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

在信息中:

public void write(Intent intent) {
    Bundle b = new Bundle();
    b.putInt(AppConstants.ID_KEY, id);
    ... //many other attributes
    intent.putExtra(AppConstants.BUNDLE_NAME, b);
}
public static Info read(Bundle bundle) {
    Info info = new Info();
    info.setId(bundle.getInt(AppConstants.ID_KEY));
    ... //many other attributes
    return info;
}
Run Code Online (Sandbox Code Playgroud)

在MapViewActivity(Activity 2)中:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_view);

    Bundle extras = …
Run Code Online (Sandbox Code Playgroud)

null android bundle android-intent

6
推荐指数
1
解决办法
2万
查看次数

Grails自动重新加载新的控制器动作

我有

  1. 创建了新的Grails 2.4.3项目
  2. 创建 TestController
  3. 设置grails.reload.enabled = trueBuildConfig.groovy
  4. 运行应用程序 grails -reloading run-app

我的控制器动作代码:

def index() {
    render "test"
}
Run Code Online (Sandbox Code Playgroud)

当我将字符串更改testtest2- 时,我在控制台中看到(在Eclipse中):

..................
|Compiling 1 source files
Run Code Online (Sandbox Code Playgroud)

重新加载页面后,我看到了test2- 好的.

但是当我尝试添加新方法时:

def test3() {
    render "test3"
}
Run Code Online (Sandbox Code Playgroud)

我知道了:

错误结果

为什么?为什么连网址都没有?

示例 - 操作不存在: 在此输入图像描述

有趣的是 - 当我创建一个全新的控制器index时,新创建的控制器的动作......

编辑

过了一会儿,我决定选择弹簧靴,事实上 - 它也没有用.我认为springloaded是这里的问题,因为它没有选择添加新方法@Controller

grails groovy reload spring-loaded grails-2.4

6
推荐指数
1
解决办法
2378
查看次数

Grails GORM:列出所有嵌套属性

我的(简化)域模型如下所示:

class Student { 
    static hasMany = [professions:StudentProfession];
}

class StudentProfession { 
    static belongsTo = [student:Student];
    Profession profession;
}

class Profession { 
    String name;
}
Run Code Online (Sandbox Code Playgroud)

什么是最有效的方式:

列出所有被授予"程序员"和"经理"职业的学生

在查询数据库后,我是否被迫过滤掉它们?

students = students.findAll { student -> 
    student.professions.find { professionNames.contains(it.profession.name) } != null
}
Run Code Online (Sandbox Code Playgroud)

grails groovy grails-orm

2
推荐指数
1
解决办法
1620
查看次数

解析PHP中的JSON转义JSON

我是PHP世界的新手,我在PHP中解析JSON时遇到了问题.我想使用Apache HttpClient 4.x和我的Java客户端将数据发布到PHP脚本Gson.

我的JSON:

[{"Knt_KntWatchId":"15","type":"INSERT","Knt_Nazwa1":"a"},{...},...]
Run Code Online (Sandbox Code Playgroud)

我用Java发送它HttpClientGson:

    List<Contact> contacts = ...;
    HttpPost post = new HttpPost(CONTACTS_SERVICE);
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("key", AppConstants.KEY));
    nameValuePairs.add(new BasicNameValuePair("data", new Gson().toJson(contacts)));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    post.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Run Code Online (Sandbox Code Playgroud)

在页面上:

if (isset($_POST['data'])) {
    $data = $_POST['data'];
    $json = json_decode($data, true);
    var_dump($json);
    var_dump($data);
Run Code Online (Sandbox Code Playgroud)

我得到的是:

NULL string(3651) "[{\"Knt_KntWatchId\":\"15\",\"type\":\"INSERT\",\"Knt_Nazwa1\":\"a\"},...
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它运转起来?

PHP 5.2 - 无法使用 json_last_error()

php java parsing json apache-httpclient-4.x

1
推荐指数
1
解决办法
2925
查看次数

java中的布尔赋值

你能解释这个任务吗?这是什么意思?

boolean activityExists = testIntent.resolveActivity(pm) != null;
Run Code Online (Sandbox Code Playgroud)

java android

0
推荐指数
1
解决办法
230
查看次数