Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  how to read keyboard and mouse input when window not in focus( if possible?)  (Read 1170 times)
0 Members and 1 Guest are viewing this topic.
Offline h3ckboy

JGO Coder


Medals: 5



« Posted 2011-07-28 09:39:54 »

Well, first off I know a lot of you think I am writing  keylogger, and I s'pose I technically am. BUT not for any illegal intentions I assure you.

My plan is to write 2 programs, on the reads input, and then saves everything I did (or atleast the basics of it), and then another that reads the file and does the stuff(this one I know how to do).

But when I thought about itm ore, I realized that I wouldn't be able to listen to the input because my program would not be in focus.

So, if anybody has any suggestions, I would be very grateful Smiley

Thanks in advance,
h3ckboy
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-07-28 10:32:41 »

I don't believe this is possible with the current standard Java library.

Offline Dx4

Junior Member


Medals: 5



« Reply #2 - Posted 2011-07-28 10:49:53 »

Well, first off I know a lot of you think I am writing  keylogger, and I s'pose I technically am. BUT not for any illegal intentions I assure you.

My plan is to write 2 programs, on the reads input, and then saves everything I did (or atleast the basics of it), and then another that reads the file and does the stuff(this one I know how to do).

But when I thought about itm ore, I realized that I wouldn't be able to listen to the input because my program would not be in focus.

So, if anybody has any suggestions, I would be very grateful Smiley

Thanks in advance,
h3ckboy

here

1  
2  
3  
4  
5  
package yourpckage;

class yourclass {
 public static native int GetAsyncKeyState ( int v );
}


and

1  
2  
JNIEXPORT jint JNICALL Java_yourpackage_yourclass_GetAsyncKeyState
  (JNIEnv *, jclass, jint v) { return GetAsyncKeyState(v); }


remember to #include < windows.h > !!

example of usage:

1  
2  
3  
4  
5  
6  
for (int i = 0; i < 256; i++) {
 final int vk = VK_BASE + i;
 if (yourpackage.yourclass.GetAsyncKeyState(vk) > 0) {
   fireKeyDown(vk);
 }
}


define VK_BASE to be the base of all virtual keys you want to read.

- David
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2011-07-28 11:05:12 »

All that code is necessary and stuff, but don't forget to explain how to compile the C code, link it to Java using javah, and using System.loadLibrary

Offline tom
« Reply #4 - Posted 2011-07-28 11:09:05 »

JInput

Offline h3ckboy

JGO Coder


Medals: 5



« Reply #5 - Posted 2011-07-28 11:59:19 »

JInput soudns much simpler Smiley. I'll google around for stuff about that, and I think there are tut's here.

Thank you dx4 though Smiley. If I run into trouble I will give that a deeper look

[EDIT]
haha, a quick google search sent me right back to javagaming Smiley
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #6 - Posted 2011-07-28 12:28:45 »

JInput will do it.

On windows you'll need to exclusively use the directx plugin, which captures mouse and keyboard input for the system rather than a window. There are details on how to do that in the JInput forum on JGO Smiley

Endolf

Offline h3ckboy

JGO Coder


Medals: 5



« Reply #7 - Posted 2011-07-28 17:26:19 »

aight, thanks for the tip Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (7 views)
2014-10-02 14:36:20

Pippogeek (41 views)
2014-09-24 16:13:29

Pippogeek (32 views)
2014-09-24 16:12:22

Pippogeek (22 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (30 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!