我要用javaSwing 做类似网吧管理系统一样,具有和系统一样的锁屏功能,除了关机和输入正确的口令。什么都不能做。我现在已经实现以一部分,但是几个系统热键没有屏蔽所以还是能退出来。所以我想问一下在程序里面捕获到了用户的按键事件后怎么把系统带的热键功能屏蔽。

解决方案 »

  1.   

    http://topic.csdn.net/u/20090715/09/59336412-1626-45e5-9624-5961ec5fe6ea.html
      

  2.   

    好像先要获取用户按下的键 
    然后在根据用户按下的键判断是否属于系统热键 
    如果属于 就返回true
    否则就返回FALSE
    当然 这样做的话 就有一个很大的缺点 就是 你不知道他系统有多少热键 包括其他软件自带的 你判断的话 就有一点比较多 比较麻烦 不过我没有想到其他什么办法
      

  3.   

    查资料问朋友都说,实现该功能必须调用系统的钩子函数,在java中也必须通过jni调用来实现,通过c调用系统的钩子函数然后再通过jni调用。看来实现此功能要去学C和jni了。
      

  4.   

    <?xml version="1.0" encoding="UTF-8"?><project basedir="." default="war" name="bid">
    <property name="app-name" value="bid" />
    <property name="release-version" value="20060720-1549" />
    <property name="src" value="src" />
    <property name="dist" value="dist" />
    <property name="classes" value="WebRoot/WEB-INF/classes" />
    <property name="lib" value="WebRoot/WEB-INF/lib" />
    <property name="ext-lib" value="ext-lib" />
    <property name="charset" value="UTF-8" />
    <property name="javadoc-packagenames" value="com.safemore.bid,com.safemore.bid.bid,com.safemore.bid.common,com.safemore.bid.issue,com.safemore.bid.logon,com.safemore.bid.util" /><patternset id="resources">
      <include name="**/*.jpe" />
      <include name="**/*.jpeg" />
      <include name="**/*.rmf" />
      <include name="**/*.wav" />
      <include name="**/*.midi" />
      <include name="**/*.mid" />
      <include name="**/*.au" />
      <include name="**/*.gif" />
      <include name="**/*.png" />
      <include name="**/*.jpg" />
      <include name="**/*.aiff" />
      <include name="**/*.properties" />
      <include name="**/*.txt" />
      <include name="**/*.xml" />
    </patternset><path id="classpath">
      <pathelement location="${dist}" />
      <fileset dir="${lib}">
       <include name="*.jar" />
      </fileset>
      <fileset dir="${ext-lib}">
       <include name="*.jar" />
      </fileset>
    </path><target name="init">
      <mkdir dir="${dist}" />
      <mkdir dir="${classes}" />
    </target><target name="war" depends="resource, jar">
      <!--touch file="WEB-INF/web.xml"/-->
      <war compress="false" destfile="${dist}/${app-name}-${release-version}.war" webxml="WebRoot/WEB-INF/web.xml">
       <fileset dir="WebRoot">
        <include name="**/*.*" />
        <exclude name="WEB-INF/" />
       </fileset>
       <fileset dir="WebRoot">
        <include name="WEB-INF/*.*" />
        <exclude name="WEB-INF/web.xml" />
        <exclude name="WEB-INF/${app-name}.xml" />
        <exclude name="lib/" />
       </fileset>
       <lib dir="${lib}">
        <include name="*.jar" />
       </lib>
       <!--
       <lib dir="${dist}">
        <include name="*.jar" />
       </lib>
       -->
       <classes dir="${classes}" />
      </war>
    </target><target name="resource">
      <copy todir="${classes}">
       <fileset dir="${src}">
        <patternset refid="resources" />
       </fileset>
      </copy>
    </target><target name="clean">
      <delete dir="${classes}" />
      <delete dir="${dist}" />
    </target><target name="compile" depends="init">
      <javac classpathref="classpath" debug="true" deprecation="false" destdir="${classes}" nowarn="false" encoding="${charset}">
       <src path="${src}" />
      </javac>
    </target><target name="jar" depends="resource, compile, init">
      <jar compress="false" destfile="${dist}/${app-name}-${release-version}.jar">
       <fileset dir="${classes}">
        <include name="**/*.class" />
        <patternset refid="resources" />
       </fileset>
      </jar>
    </target><target name="rejar" depends="clean, jar" /><target name="ear" depends="war">
      <ear destfile="${dist}/${app-name}-${release-version}.ear" appxml="META-INF/application-j1.3.xml">
       <fileset dir="${dist}" includes="${app-name}-${release-version}.war" />
      </ear>
    </target><target name="release" depends="war">
      <zip destfile="${dist}/${app-name}-${release-version}.zip">
       <zipfileset dir="${dist}" includes="${app-name}-${release-version}.war" prefix="." />
       <zipfileset dir="db" includes="*.*" prefix="db" />
       <zipfileset dir="doc" includes="*.*" prefix="doc" />
      </zip>
    </target><target name="javadoc">
      <javadoc encoding="${charset}" charset="${charset}" access="public" author="true" destdir="${dist}/javadoc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" source="1.5" splitindex="true" use="true" version="true" packagenames="${javadoc-packagenames}" sourcepath="${src}" classpathref="classpath" />
    </target>
    </project>
      

  5.   

    <!--Ant(another neat tool---另一个整洁的工具)--><?xml version="1.0"?>
    <project default="dist" name="Project A">
        <description>
             一段描述信息,没有实际作用。
        </description>
        <!--property 元素相当于变量,存放一定的值,一旦给定以后不能改变,只能通过控制台命令行给初始值。
                     一般用 value 给其赋值,这里用 location 代替 value 是因为 location 属性专门设
                     计用于以平台无关的方式包含文件系统路径,也就是当前路径。-->
        <property name="srcDir" location="."/>
        <property name="buildDir" location="classes"/>
        <property name="distDir" location="dist"/>
        
        <!--一个target 元素就是一个任务,一个步骤,如果命令行没有指定开始任务,则由 project 元素的 default 属性决定要执行的任务-->
        <target name="init" description="在元素中指定描述信息!">
            <echo message="这里的信息将被输出到控制台!">
            <!--tstamp 元素一般不定义属性和内容,不产生任何输出;相反,它根据当前系统时间和日期设置 Ant 以下属性:
             属性                 说明                                     例子
             DSTAMP             设置为当前日期,默认格式为yyyymmdd         20031217
             TSTAMP             设置为当前时间,默认格式为hhmm             1603
             TODAY             设置为当前日期,带完整的月份             2003 年12 月17 日-->
            <tstamp/>
            <!--mkdir 元素用来创建目录 dir 属性用来指定目录路径-->
            <!--delete 元素用来删除目录 $ 引用 property 元素指定的 name 为 buildDir 的属性变量-->
            <mkdir dir="$"/>
            <mkdir dir="$"/>
            <!--文件操作:
                 <copy file="src/Test.java" tofile="src/TestCopy.java"/> 把文件 Test.java 拷贝一份 TestCopy.java 
                 <move file="src/Test.java" tofile="src/TestCopy.java"/> 把文件 Test.java 重新命名为 TestCopy.java
                 <copy file="src/Test.java" todir="archive"/> 把文件 Test.java 从 src 目录复制一份到 archive 目录下
                 <move file="src/Test.java" todir="archive"/> 把文件 Test.java 从 src 目录下移动到 archive 目录下
                 <replace file="input.txt" token="old" value="new"/>replace 任务,它执行文件中的查找和替换操作。
                 token 属性指定要查找的字符串,
                 value 属性指定一个新的字符串,
                 查找到的标记字符串的所有实例都被替换为这个新的字符串.
                 替换操作将在文件本身之内的适当位置进行。为了提供更详细的输出,可把 summary 属性设置为
                 true。这将导致该任务输出找到和替换的标记字符串实例的数目。
                 <copy todir="archive">---使用模式匹配复制多个文件
                     <fileset dir="src">--fileset 代替 file 属性
                         <include name="*.java"/>--包含 src 目录下所有的 *.java 文件
                         <exclude name="*.class"/>--不包含 src 目录下所有的 *.class 文件
                     </fileset>
                 </copy>-->
        </target>    <!--target 元素的 depends 属性用来设置多个 target 元素之间的依赖关系,如果要执行某个任务,必须先执行 depends 属性指定的所有
             它所依赖的 target 元素,只有它所依赖的所有 target 元素都执行完了才能执行它自己-->
        <target name="com" depends="init">
            <!--javac 元素把 srcdir 指定目录下所有 *.java 文件编译成 *.class 文件到 destdir 指定的目录下!
                 如果不指定 destdir 属性,那么默认编译到同一目录下。其他属性:
                  classpath:等价于javac 的-classpath 选项。
                  debug="true":指示编译器应该带调试信息编译源文件。
                  fork="true":当你希望指定编译器的某些内存选项,或者需要使用一种不同级别的编译器的时候。该属性设置为“true”
                  executable="d:sdk141 injavac":指定一个不同的 javac 可执行文件。
                  memoryMaximumSize="128m":向上边指定的 javac 传递一个最大内存设置-->
            <javac srcdir="$" destdir="$"/>
        </target>    <target name="dist" depends="com">
            <!--jar 元素:在编译 Java 源文件之后,结果类文件通常被打包到一个 JAR 文件中,这个文件类似 zip 归档文
                 件。每个 JAR 文件都包含一个清单文件,它可以指定该 JAR 文件的属性。
                 还可以把目录下的所有内容打包为 WAR 文件
                 destfile:打包后的文件全名
                 basedir:要打包的文件路径-->
            <jar destfile="$/package-$.jar" basedir="$">
                <!--manifest 属性允许指定一个用作该 JAR 文件的清单的文件。清单文件的内容还可以使用 manifest
                     任务在生成文件中指定。这个任务能够像文件系统写入一个清单文件,或者能够实际嵌套在 jar 之
                     内,以便一次性地创建清单文件和 JAR 文件。-->
                <manifest>
                    <attribute name="Built-By" value="$"/>
                    <attribute name="Main-Class" value="package.Main"/>
                </manifest>
            </jar>
            <jar destfile="$/package-src-$.jar" basedir="$"/>
        </target>    <target name="zip" depends="dist">
            <!--zip 元素用来创建 zip 包,和 jar 元素相似-->
            <zip destfile="output.zip" basedir="output"/>
            <!--相同的语法也可用于创建 tar 文件。 还可以使用 GZip 和 BZip 任务来压缩文件。-->
            <tar destfile="output.tar" basedir="output"/>
            <gzip src="output.tar" zipfile="output.tar.gz"/>
            <!--解压缩和提取文件同样也很简单.-->
            <unzip src="output.tar.gz" dest="extractDir"/>
            <!--还可以包括 overwrite 属性来控制覆盖行为。默认设置是覆盖与正在被提取的归档文件中的条目相
                 匹配的所有现有文件。相关的任务名称是 untar、unjar、gunzip 和 bunzip2。-->
        </target>    <!--编写一个 clean目标来从目标目录移除生成的任何类文件是个很好的习惯。如果想要确
             保所有源文件都已编译,就可以使用这个任务。这种行为刻画了 Ant 的许多任务的特点:
             如果某个任务能够确定所请求的操作不需要执行,那么该操作就会被跳过。-->
        <target name="clean">
            <delete dir="$"/>
            <delete dir="$"/>
        </target>
    </project>
      

  6.   

    <?xml version="1.0" encoding="gbk" ?>
    <!-- ant调用cmd命令行,ant运行参数有空格的jar程序 -->
    <project name="ant执行(调用)cmd命令行" default="make_jar_for_test5" basedir=".">
    <property name="jarDir" value="E:\大地工作\updateBak\ant使用大全(我的)\用ant 压缩备份" />
    <property name="testCopyFormDir" value="C:\t1" />
    <property name="testCopyToDir" value="C:\t1\update" /><target name="test1">
       <!-- 1.直截执行一句命令行 -->
       <!-- arg line 适合于参数中没有空格的情况 -->
       <exec executable="cmd" failonerror="true">
        <arg line="/c echo %path%" />
       </exec>
    </target><target name="test2">
       <!-- 
       2.这里演示的是ant中执行批处理文件“c:/cpy.bat”文件内容为一句命令,如下:
       java -classpath "${jarDir}/copyTool_fat.jar" cmd.file.CopyFile "D:/My Documents" "${testCopyFormDir}" -1
       -->  
       <exec executable="cmd" failonerror="true">
        <arg line="/c c:/cpy" />
       </exec>
    </target><target name="test3">
       <!-- 
       3.ant中以参数带空格的命令行的方式运行一个jar程序,等效执行这个批处理,如下:
       java -classpath "${jarDir}/copyTool_fat.jar" cmd.file.CopyFile "D:/My Documents" "${testCopyFormDir}" -1
       -->
       <exec executable="cmd" failonerror="true">
        <arg value="/c" />
        <arg value="java" />
        <arg value="-classpath" />
        <arg value="${jarDir}/copyTool_fat.jar" />
        <arg value="cmd.file.CopyFile" />
        <arg value="${testCopyFormDir}" />
        <arg value="${testCopyToDir}" />
        <arg value="-2" />
       </exec>
    </target><!-- 有关java方式,参考ant文档:ant\docs\manual\tasksoverview.html --><target name="test4">
       <!--
       4.ant中以参数带空格的java方式运行一个jar程序,等效执行这个批处理,如下:
       java -classpath "${jarDir}/copyTool_fat.jar" cmd.file.CopyFile "D:/My Documents" "${testCopyFormDir}" -1   参数jar/classname不可同时用,用jar的时候要有入口类 ,这里用的是参数classname
       -->
       <java failonerror="true" classname="cmd.file.CopyFile">
        <arg value="${testCopyFormDir}" />
        <arg value="${testCopyToDir}" />
        <arg value="-2" />
        <classpath>
         <pathelement location="${jarDir}/copyTool_fat.jar" />
        </classpath>
       </java>
    </target>
    <target name="make_jar_for_test5">
       <!-- 创建jar文件。
       如果用bat文件创建,批处理语句如:
       jar cvfm prj.jar prj_classes/META-INF/MANIFEST.MF -C prj_classes .
       rem bat文件和classes目录在同一父级目录里面   其中MANIFEST.MF内容为3句,如下:
       Manifest-Version: 1.0
       Created-By: Fat Jar Eclipse Plug-In
       Main-Class: cmd.file.CopyFile
       -->
       <jar jarfile="copyTool.jar" basedir="${jarDir}\copyTool\bin">
        <manifest>
         <attribute name="Manifest-Version" value="1.0"/>
         <attribute name="Created-By" value="chenxiaowen"/>
         <!--如果想要以 <java jar="copyTool.jar"/ ……> 的方式运行就必须列出引用到的jar文件,否则报错:
         java.lang.NoClassDefFoundError: org/apache/commons/lang/time/DateUtils
         并且在调用的时候要保证列出的jar文件的位置没有发生变化(例子参见 test5 )
         -->
         <attribute name="Class-Path" value="copyTool\lib\commons-io-1.4.jar copyTool\lib\commons-lang-2.4.jar"/>
         <attribute name="Main-Class" value="cmd.file.CopyFile"/>
        </manifest>
       </jar>
    </target>
    <!-- <classpath refid="libs" /> -->
        <path id="libs">
         <pathelement path="${jarDir}"/>
       <fileset dir="${jarDir}">
                <include name="**/*.jar"/>
            </fileset>
       <!-- pathelement path="commons-io-1.4.jar" / -->
       <!--pathelement location="commons-lang-2.4.jar" / -->
        </path><target name="test5">
       <!--  
       使用多个jar文件(没有用jar fat打包为一个)
       ant中以参数带空格的java方式运行一个jar程序。
       参数jar/classname不可同时用,用jar的时候要有入口类 ,这里用的是参数jar
       -->
       <java dir="${jarDir}" jar="${jarDir}/copyTool.jar" fork="true" maxmemory="128m" failonerror="true">
        <arg value="${testCopyFormDir}" />
        <arg value="${testCopyToDir}" />
        <arg value="-2" />
        <!-- 无需这里指定 classpath,classpath已经在创建 copyTool.jar 的时候指定了 -->
       </java>
    </target>
    <target name="test6">
       <!--
       使用1个jar文件(用jar fat打包为一个)
       ant中以参数带空格的java方式运行一个jar程序。
       参数jar/classname不可同时用,用jar的时候要有入口类 ,这里用的是参数jar
       -->
       <java failonerror="true" fork="true" jar="${jarDir}/copyTool_fat.jar" dir="${jarDir}/">
        <arg value="${testCopyFormDir}" />
        <arg value="${testCopyToDir}" />
        <arg value="-2" />
       </java>
    </target>
    <target name="test7">
       <!--
       使用多个jar文件(没有用jar fat打包为一个)
       ant中以参数带空格的java方式运行一个jar程序。  
       参数jar/classname不可同时用,用jar的时候要有入口类 ,这里用的是参数classname
      
       以批处理方式执行需要多个jar文件的程序所用的命令行如:
       java -classpath ".\copyTool.jar;.\commons-io-1.4.jar;.\commons-lang-2.4.jar" cmd.file.CopyFile "D:/My Documents" "${testCopyFormDir}" -1
       java -classpath ".\copyTool.jar;.\lib\commons-io-1.4.jar;.\lib\commons-lang-2.4.jar" cmd.file.CopyFile "D:/My Documents" "${testCopyFormDir}" -1
       -->
       <java failonerror="true" classname="cmd.file.CopyFile" fork="true">
        <arg value="${testCopyFormDir}" />
        <arg value="${testCopyToDir}" />
        <arg value="-2" />
        <!-- 所用的jar文件在这个引用里面 -->
        <classpath refid="libs"/>
       </java>
    </target></project>
      

  7.   

    先学调用c的dll就行了,然后叫朋友写个dll,
      

  8.   

    python 打包exe:
    -------------------------------------------------------------------------------
    # -*- coding: UTF-8 -*-
    #Copyright (C) 2007, Huawei Technologies Co., Ltd. All rights reserved.
    # This setup script builds a single-file Python inprocess COM server.
    #
    from distutils.core import setup
    import py2exe
    import sys# If run without args, build executables, in quiet mode.
    if len(sys.argv) == 1:
        sys.argv.append("py2exe")
        sys.argv.append("-q")################################################################
    # pywin32 COM pulls in a lot of stuff which we don't want or need.excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon",
                "pywin.dialogs", "pywin.dialogs.list","win32com.server"]includes = []
    packages = []options = {
        "bundle_files": 1, # create singlefile exe
        "compressed": 1, # compress the library archive
        "optimize": 0,
        "excludes": excludes,
        "includes": includes,
        "packages": packages,
        "dll_excludes": ["w9xpopen.exe", "zlib.pyd", "bz2.pyd", "_ssl.pyd", "_socket.pyd"] # we don't need this
        }
    setup(
        options = {"py2exe": options},
        zipfile = None,
        #zipfile = "ma.dat", # append zip-archive to the executable.
        console = [{'script':'gridSizer.py',
                    'icon_resources':[(1,r"F:/pythonTest/MyProgramT/BIN/images/huawei64.ico")],
                    }],
        )
      

  9.   

    python 打包exe:
    -------------------------------------------------------------------------------
    # -*- coding: UTF-8 -*-
    #Copyright (C) 2007, Huawei Technologies Co., Ltd. All rights reserved.
    # This setup script builds a single-file Python inprocess COM server.
    #
    from distutils.core import setup
    import py2exe
    import sys# If run without args, build executables, in quiet mode.
    if len(sys.argv) == 1:
        sys.argv.append("py2exe")
        sys.argv.append("-q")################################################################
    # pywin32 COM pulls in a lot of stuff which we don't want or need.excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon",
                "pywin.dialogs", "pywin.dialogs.list","win32com.server"]includes = []
    packages = []options = {
        "bundle_files": 1, # create singlefile exe
        "compressed": 1, # compress the library archive
        "optimize": 0,
        "excludes": excludes,
        "includes": includes,
        "packages": packages,
        "dll_excludes": ["w9xpopen.exe", "zlib.pyd", "bz2.pyd", "_ssl.pyd", "_socket.pyd"] # we don't need this
        }
    setup(
        options = {"py2exe": options},
        zipfile = None,
        #zipfile = "ma.dat", # append zip-archive to the executable.
        console = [{'script':'gridSizer.py',
                    'icon_resources':[(1,r"F:/pythonTest/MyProgramT/BIN/images/huawei64.ico")],
                    }],
        )
      

  10.   

    srcZipFile是你需要解压的包文件,destPath是解压后的文件保存的路径。
    def UnZipFile(srcZipFile,destPath):
        tmpFile = None
        tmpZip = None
        nameList = []
        try:
            if os.path.isfile(srcZipFile):
                tmpFile = file(srcZipFile,'rb')
            else:
                return (False, "Not zip file!")
            try:
                tmpZip = zipfile.ZipFile(tmpFile,"r")
            except:
                print "Unzip Failed!"
                return (False, "Unzip Failed!")
            if not os.path.exists(destPath):
                os.makedirs(destPath)
            nameList = tmpZip.namelist()
            for name in nameList:
                filePath = os.path.join(destPath,name)
                content = tmpZip.read(name)
                if name.endswith('/'):
                    if not os.path.exists(filePath):
                        os.makedirs(filePath)
                else:
                    pos = filePath.rfind("/")
                    if -1 != pos:
                        tmpPath = filePath[:pos]
                        if not os.path.exists(tmpPath):
                            os.makedirs(tmpPath)
                    tmpWriteFile = file(filePath,'wb+')
                    tmpWriteFile.write(content)
                    tmpWriteFile.close()
        except:
            if tmpFile:
                tmpFile.close()
            if tmpZip:
                tmpZip.close() 
            message = traceback.format_exception(*sys.exc_info())
            print "".join(message)
            return (False, "")
        if tmpFile:
            tmpFile.close()
        if tmpZip:
            tmpZip.close() 
        return (True, nameList)