By key combination i mean a succession of keystrokes.Suppose you provided : -abcd
Then whenever you type "abcd" at the keyboard...then it can perform the actions provided in the following inputs(like a message box with your msg,running a program).
It also emulates the backspace key so:-
abcd=abcp[BACKSPACE]d ;where [BACKSPACE] is the pressing of backspace key.
Note:- It can lag a low RAM machine and can even crash...(uses the unpopular GetAsyncKeyState() function)
(More in ReadMe file)
Uses:-Depends....but which comes first to mind is to freak out someone.
/*
Title:- Flashcore KeyComb v1.1 by Warrior
Author:- Warrior@programmer.net
Homepage:- www.flashcore-hq.blogspot.com
Copyright (c) 2010 by Warrior@programmer.net
Please report bugs at Warrior@programmer.net
I have no responsibility for the damage caused by the program
If you modify this source code keep a record of it.
This software is licenced under the GNU General Public Licence(GPL).
Licence:- http://www.gnu.org/licenses/gpl.html
*/
#include <stdio.h>
#include <ctype.h>
#include <windows.h>
#define BUFF 512
typedef struct{
struct{
char key_buff[BUFF]; /*Buffer for keystrokes*/
int bpos; /*Position of KEY_BUFF*/
}buff;
struct{
char keys[50]; /*Key combination to match*/
int kpos; /*Number of characters matched*/
}key;
char msg[512]; /*Message to display on match*/
char prog[512]; /*Program to run on match*/
}KEYCOMB ;
KEYCOMB kc;
void strtoupper(char *s)
{
while(*s=toupper(*s))
s++;
}
int get_input()
{
int l;
fputs("*****Flashcore KeyComb v1.1 by Warrior*****\n\n",stdout);
fputs("Enter keys combination:[Max length:50]:",stdout);
fgets(kc.key.keys,sizeof(kc.key.keys)/sizeof(kc.key.keys[0]),stdin);
l=strlen(kc.key.keys);
if(l==1){
fputs("Invalid Input!\n",stderr);
return 0;
}
/*Condition false only if input length is more then buffer,in that case the last character is not newline*/
if(kc.key.keys[l-1]=='\x0A')
kc.key.keys[l-1]=0;
fputs("\n[Below are optional inputs.Enter just a newline for no input]\n\n",stdout);
fputs("Enter the message to be displayed:",stdout);
fgets(kc.msg,sizeof(kc.msg)/sizeof(kc.msg[0]),stdin);
l=strlen(kc.msg);
if(kc.msg[l-1]=='\x0A')
kc.msg[l-1]=0;
fputs("Enter the program to run on a match:",stdout);
fgets(kc.prog,sizeof(kc.prog)/sizeof(kc.prog[0]),stdin);
l=strlen(kc.prog);
if(kc.prog[l-1]=='\x0A')
kc.prog[l-1]=0;
fputs("\n\n[Now KeyComb will run silently.....]\n",stdout);
return 1;
}
void hideme()
{
HWND hwnd=FindWindow(NULL,"Flashcore KeyComb v1.1");
ShowWindow(hwnd,SW_HIDE);
}
/*GetAsyncKeyState returns last key pressed.
This function ensures that the subsequent calls to the GetAsyncKeyState
function don't return the keys pressed when inputting
*/
void flush_keys()
{
int t;
for(t=0x0;t<0xFE;t++) /*Flush any possible key*/
GetAsyncKeyState(t);
}
/*Pops all keys from the buffer and zeroes the number of keys matched*/
void reset()
{
kc.buff.bpos=0;
kc.key.kpos=0;
}
/*Tests whether the keys combination is there in the buffer*/
int key_cmp()
{
int i;
int j;
char *buffer=kc.buff.key_buff;
char *keys=kc.key.keys;
i=0;
while(1){
for(;i<kc.buff.bpos;i++)
if(keys[0]==buffer[i])break;
for(j=1,i+=1;keys[j] && i<kc.buff.bpos;i++,j++)
if(keys[j]!=buffer[i])break;
if(!keys[j])return 1;
if(i==kc.buff.bpos)break;
}
return 0;
}
/*Pushes a key in the buffer*/
void push_key(int k)
{
if(kc.buff.bpos==sizeof(kc.buff.key_buff)/sizeof(kc.buff.key_buff[0]))
reset();
kc.buff.key_buff[kc.buff.bpos++]=k;
}
/*Pops a key from the buffer*/
void pop_key()
{
if(kc.buff.bpos!=0)
--kc.buff.bpos;
else
kc.key.kpos=0;
}
int main(int argc,char *argv[])
{
int c;
char *key=kc.key.keys;
int *i=&kc.key.kpos;
SetConsoleTitle("Flashcore KeyComb v1.1");
if(!get_input())
return -1;
flush_keys();
strtoupper(kc.key.keys);
Sleep(2000);
hideme();
for(;;){
while(1){
for(c=0x0;c<0xBE;c++){
if(GetAsyncKeyState(c)&1==1)break;
/*Sleep(20);*/
}
if(c!=0xBE)break;
}
push_key(c);
if(key[*i]==c){
if(*i==strlen(key)-1){
if(key_cmp()){
if(kc.prog[0])
ShellExecute(NULL,"open",kc.prog,NULL,NULL,SW_SHOW);
if(kc.msg[0])
MessageBox(NULL,kc.msg,"KeyComb v1.1",MB_ICONASTERISK);
/*The keys combination was found in the keystoke buffer,start off again*/
reset();
}
}
else
*i+=1;
}
else if(c=='\x08'){/*Emulates backspace key*/
pop_key();/*pop the backspace key itself*/
pop_key();/*delete the last character,just as backspace do*/
}
}
return 0;
}
(Maybe in the later version i will try to use the "keyboard buffer" directly)
Warrior
Source + Executable :-
Attached Files
Edited by Warrior, 07 July 2010 - 12:26 AM.


Sign In
Create Account



Back to top









